aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/hash
diff options
context:
space:
mode:
authorAndrew Moreland <andy@andymo.org>2009-08-09 15:38:30 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2009-08-09 17:32:04 -0700
commitca92d44e7637ae6d28d6b88b67873d2795290cb5 (patch)
treeb7237174a7289ba34b6bbf9569521c6786d52f4e /activesupport/lib/active_support/core_ext/hash
parent0af4b0755f507d41590b5315966c9a20949f79f9 (diff)
downloadrails-ca92d44e7637ae6d28d6b88b67873d2795290cb5.tar.gz
rails-ca92d44e7637ae6d28d6b88b67873d2795290cb5.tar.bz2
rails-ca92d44e7637ae6d28d6b88b67873d2795290cb5.zip
Support deep-merging HashWithIndifferentAccess.
[#2732 state:committed] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activesupport/lib/active_support/core_ext/hash')
-rw-r--r--activesupport/lib/active_support/core_ext/hash/deep_merge.rb9
1 files changed, 5 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/core_ext/hash/deep_merge.rb b/activesupport/lib/active_support/core_ext/hash/deep_merge.rb
index ffde34a741..24d0a2a481 100644
--- a/activesupport/lib/active_support/core_ext/hash/deep_merge.rb
+++ b/activesupport/lib/active_support/core_ext/hash/deep_merge.rb
@@ -1,11 +1,12 @@
class Hash
# Returns a new hash with +self+ and +other_hash+ merged recursively.
def deep_merge(other_hash)
- merge(other_hash) do |key, oldval, newval|
- oldval = oldval.to_hash if oldval.respond_to?(:to_hash)
- newval = newval.to_hash if newval.respond_to?(:to_hash)
- oldval.is_a?( Hash ) && newval.is_a?( Hash ) ? oldval.deep_merge(newval) : newval
+ target = dup
+ other_hash.each_pair do |k,v|
+ tv = target[k]
+ target[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? tv.deep_merge(v) : v
end
+ target
end
# Returns a new hash with +self+ and +other_hash+ merged recursively.