Class: Hash
Instance Method Summary collapse
-
#deep_merge(other) ⇒ Object
Merge not only the hashes, but all nested hashes as well.
-
#deep_merge!(other) ⇒ Object
Merge not only the hashes, but all nested hashes as well.
Instance Method Details
#deep_merge(other) ⇒ Object
Merge not only the hashes, but all nested hashes as well. Written by Stefan Rusterholz (apeiros) from www.ruby-forum.com/topic/142809
14 15 16 17 18 19 20 |
# File 'lib/fidgit/standard_ext/hash.rb', line 14 def deep_merge(other) merger = lambda do |key, a, b| (a.is_a?(Hash) && b.is_a?(Hash)) ? a.merge(b, &merger) : b end merge(other, &merger) end |
#deep_merge!(other) ⇒ Object
Merge not only the hashes, but all nested hashes as well. Written by Stefan Rusterholz (apeiros) from www.ruby-forum.com/topic/142809
4 5 6 7 8 9 10 |
# File 'lib/fidgit/standard_ext/hash.rb', line 4 def deep_merge!(other) merger = lambda do |key, a, b| (a.is_a?(Hash) && b.is_a?(Hash)) ? a.merge!(b, &merger) : b end merge!(other, &merger) end |