Module: Hashie::Extensions::DeepMerge

Defined in:
lib/hashie/extensions/deep_merge.rb

Instance Method Summary collapse

Instance Method Details

#deep_merge(other_hash, &block) ⇒ Object

Returns a new hash with +self+ and +other_hash+ merged recursively.



5
6
7
8
9
# File 'lib/hashie/extensions/deep_merge.rb', line 5

def deep_merge(other_hash, &block)
  copy = _deep_dup(self)
  copy.extend(Hashie::Extensions::DeepMerge) unless copy.respond_to?(:deep_merge!)
  copy.deep_merge!(other_hash, &block)
end

#deep_merge!(other_hash, &block) ⇒ Object

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



13
14
15
16
17
# File 'lib/hashie/extensions/deep_merge.rb', line 13

def deep_merge!(other_hash, &block)
  return self unless other_hash.is_a?(::Hash)
  _recursive_merge(self, other_hash, &block)
  self
end