Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/configy/config_store.rb
Instance Method Summary collapse
-
#deep_merge(other_hash) ⇒ Object
Returns a new hash with
self
andother_hash
merged recursively. -
#deep_merge!(other_hash) ⇒ Object
Returns a new hash with
self
andother_hash
merged recursively.
Instance Method Details
#deep_merge(other_hash) ⇒ Object
Returns a new hash with self
and other_hash
merged recursively.
6 7 8 |
# File 'lib/configy/config_store.rb', line 6 def deep_merge(other_hash) dup.deep_merge!(other_hash) end |
#deep_merge!(other_hash) ⇒ Object
Returns a new hash with self
and other_hash
merged recursively. Modifies the receiver in place.
12 13 14 15 16 17 18 |
# File 'lib/configy/config_store.rb', line 12 def deep_merge!(other_hash) other_hash.each_pair do |k,v| tv = self[k] self[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? tv.deep_merge(v) : v end self end |