module Gorillib::Hashlike::DeepMerge

Public Instance Methods

deep_merge(other_hash) click to toggle source

Returns a new hash with self and other_hash merged recursively.

# File lib/gorillib/hashlike/deep_merge.rb, line 5
def deep_merge(other_hash)
  dup.deep_merge!(other_hash)
end
deep_merge!(other_hash) click to toggle source

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

# File lib/gorillib/hashlike/deep_merge.rb, line 11
def deep_merge!(other_hash)
  other_hash.each_pair do |ok, ov|
    ov = convert_value(ov) if respond_to?(:convert_value)
    sv = self[ok]
    self[ok] = sv.is_a?(Hash) && ov.is_a?(Hash) ? sv.deep_merge(ov) : ov
  end
  self
end