Module: Akami::CoreExt::Hash

Defined in:
lib/akami/core_ext/hash.rb

Instance Method Summary collapse

Instance Method Details

#deep_merge(other_hash) ⇒ Object

Returns a new hash with self and other_hash merged recursively.



10
11
12
# File 'lib/akami/core_ext/hash.rb', line 10

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

#deep_merge!(other_hash) ⇒ Object

Returns a new Hash with self and other_hash merged recursively. Modifies the receiver in place.



16
17
18
19
20
21
22
# File 'lib/akami/core_ext/hash.rb', line 16

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