Method: Mash#deep_update

Defined in:
lib/mash.rb

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

Recursively merges this mash with the passed in hash, merging each hash in the hierarchy.



130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/mash.rb', line 130

def deep_update(other_hash)
  other_hash = other_hash.to_hash if other_hash.is_a?(Mash)
  other_hash = other_hash.stringify_keys
  other_hash.each_pair do |k,v|
    k = convert_key(k)
    self[k] = self[k].to_mash if self[k].is_a?(Hash) unless self[k].is_a?(Mash)
    if self[k].is_a?(Hash) && other_hash[k].is_a?(Hash)
      self[k] = self[k].deep_merge(other_hash[k]).dup
    else
      self.send(k + "=", convert_value(other_hash[k],true))
    end
  end
end