1 module ActiveSupport
#:nodoc:
2 module CoreExtensions
#:nodoc:
4 # Allows for deep merging
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
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
))