Class: Hash

Inherits:
Object show all
Defined in:
lib/ergane/core_ext/hash.rb

Instance Method Summary collapse

Instance Method Details

#&(other) ⇒ Object

Hash intersection by keys. Values come from the receiver.

{a: 1, b: 2} & {a: 10, c: 3}  # => {a: 1}


6
7
8
9
# File 'lib/ergane/core_ext/hash.rb', line 6

def &(other)
  shared = keys & other.keys
  shared.each_with_object({}) { |k, h| h[k] = self[k] }
end