module SugarRefinery::HashOp

Public Instance Methods

&(other) click to toggle source
# File lib/sugar_refinery/hash_op.rb, line 17
def &(other)
  Hash[ *select{ |k,v|
    other[k] == v
  }.flatten ]
end
+(*o, &block) click to toggle source
# File lib/sugar_refinery/hash_op.rb, line 23
def +(*o, &block)
  merge *o, &block
end
<<(other) click to toggle source
# File lib/sugar_refinery/hash_op.rb, line 6
def <<(other)
  case
  when other.is_a?(Hash)
    merge! other
  when other.is_a?(Enumerable) || other.respond_to?(:to_splat)
    merge! Hash[*other]
  else
    raise TypeError, 'can only append other Hashs and Enumerables (or Classes that implement to_splat)'
  end
end