Module: Nuggets::Hash::DeepMergeMixin

Included in:
Hash
Defined in:
lib/nuggets/hash/deep_merge_mixin.rb

Instance Method Summary collapse

Instance Method Details

#deep_merge(other) ⇒ Object

call-seq:

hash.deep_merge(other_hash) => aHash

Merges nested hashes recursively (see Hash#merge).



35
36
37
38
39
# File 'lib/nuggets/hash/deep_merge_mixin.rb', line 35

def deep_merge(other)
  merge(other) { |key, old, new|
    old.respond_to?(:deep_merge) ? old.deep_merge(new) : new
  }
end

#deep_merge!(other) ⇒ Object Also known as: deep_update

call-seq:

hash.deep_merge!(other_hash) => hash

Destructive version of #deep_merge.



45
46
47
# File 'lib/nuggets/hash/deep_merge_mixin.rb', line 45

def deep_merge!(other)
  replace(deep_merge(other))
end