Class: Hash
Overview
Various Hash extensions.
Direct Known Subclasses
Instance Method Summary collapse
-
#deep_merge(other_hash) ⇒ Object
Recursively merge
other_hash
intoself
and return the new hash. -
#deep_merge!(other_hash) ⇒ Object
Recursively merge and replace
other_hash
into +self.
Instance Method Details
#deep_merge(other_hash) ⇒ Object
Recursively merge other_hash
into self
and return the new hash.
7 8 9 10 11 12 13 |
# File 'lib/madvertise/ext/hash.rb', line 7 def deep_merge(other_hash) self.merge(other_hash) do |key, oldval, newval| oldval = oldval.to_hash if oldval.respond_to?(:to_hash) newval = newval.to_hash if newval.respond_to?(:to_hash) oldval.is_a?(Hash) && newval.is_a?(Hash) ? oldval.deep_merge(newval) : newval end end |
#deep_merge!(other_hash) ⇒ Object
Recursively merge and replace other_hash
into +self.
16 17 18 |
# File 'lib/madvertise/ext/hash.rb', line 16 def deep_merge!(other_hash) replace(deep_merge(other_hash)) end |