Froze rails gems
[depot.git] / vendor / rails / activesupport / lib / active_support / core_ext / hash / deep_merge.rb
1 module ActiveSupport #:nodoc:
2 module CoreExtensions #:nodoc:
3 module Hash #:nodoc:
4 # Allows for deep merging
5 module DeepMerge
6 # Returns a new hash with +self+ and +other_hash+ merged recursively.
7 def deep_merge(other_hash)
8 self.merge(other_hash) do |key, oldval, newval|
9 oldval = oldval.to_hash if oldval.respond_to?(:to_hash)
10 newval = newval.to_hash if newval.respond_to?(:to_hash)
11 oldval.class.to_s == 'Hash' && newval.class.to_s == 'Hash' ? oldval.deep_merge(newval) : newval
12 end
13 end
14
15 # Returns a new hash with +self+ and +other_hash+ merged recursively.
16 # Modifies the receiver in place.
17 def deep_merge!(other_hash)
18 replace(deep_merge(other_hash))
19 end
20 end
21 end
22 end
23 end