Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/wcc.rb

Instance Method Summary collapse

Instance Method Details

#recursive_merge(other) ⇒ Hash

Recursively merges the other hash into self while overwriting duplicate keys in self.

Parameters:

  • other (Hash)

    the hash to get merged in

Returns:

  • (Hash)

    copy of self with other hash merged in



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/wcc.rb', line 55

def recursive_merge(other)
  copy = self.dup
  other.keys.each do |k|
    if other[k].is_a?(Hash) and self[k].is_a?(Hash)
      copy[k] = copy[k].recursive_merge(other[k])
    else
      # ignore nils from other
      copy[k] = other[k] unless other[k].nil?
    end
  end
  copy
end