aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/hash/deep_merge.rb
diff options
context:
space:
mode:
authorM. Simon Borg <msimonborg@gmail.com>2017-08-15 17:21:39 -0400
committerM. Simon Borg <msimonborg@gmail.com>2017-08-16 18:35:00 -0400
commit2eacb1c30eac4058b8412527f9bda6e7ba6103d4 (patch)
tree64691bd4ff823ac3922f5c4a42085bf7e491ce72 /activesupport/lib/active_support/core_ext/hash/deep_merge.rb
parent7c839024458b1d3d912f1eee3f38691d710ebf1e (diff)
downloadrails-2eacb1c30eac4058b8412527f9bda6e7ba6103d4.tar.gz
rails-2eacb1c30eac4058b8412527f9bda6e7ba6103d4.tar.bz2
rails-2eacb1c30eac4058b8412527f9bda6e7ba6103d4.zip
faster implementation of Hash#deep_merge
add missing newline call #deep_merge instead of #dup.deep_merge! make variable and parameter naming more consistent change `_key` to `key` faster implementation of Hash#deep_merge
Diffstat (limited to 'activesupport/lib/active_support/core_ext/hash/deep_merge.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/hash/deep_merge.rb18
1 files changed, 6 insertions, 12 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 f92a2f1c2a..9bc50b7bc6 100644
--- a/activesupport/lib/active_support/core_ext/hash/deep_merge.rb
+++ b/activesupport/lib/active_support/core_ext/hash/deep_merge.rb
@@ -21,20 +21,14 @@ class Hash
# Same as +deep_merge+, but modifies +self+.
def deep_merge!(other_hash, &block)
- other_hash.each_pair do |current_key, other_value|
- this_value = self[current_key]
-
- self[current_key] = if this_value.is_a?(Hash) && other_value.is_a?(Hash)
- this_value.deep_merge(other_value, &block)
+ merge!(other_hash) do |key, this_val, other_val|
+ if this_val.is_a?(Hash) && other_val.is_a?(Hash)
+ this_val.deep_merge(other_val, &block)
+ elsif block_given?
+ block.call(key, this_val, other_val)
else
- if block_given? && key?(current_key)
- block.call(current_key, this_value, other_value)
- else
- other_value
- end
+ other_val
end
end
-
- self
end
end