Class: Hash

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

Instance Method Summary collapse

Instance Method Details

#deep_merge(other_hash) ⇒ Object



5
6
7
# File 'lib/visitors/core_ext/hash.rb', line 5

def deep_merge(other_hash)
  dup.deep_merge!(other_hash)
end

#deep_merge!(other_hash) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/visitors/core_ext/hash.rb', line 13

def deep_merge!(other_hash)
  other_hash.each_pair do |k,v|
    tv = self[k]
    self[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? tv.deep_merge(v) : v
  end
  self
end