aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorKasper Timm Hansen <kaspth@gmail.com>2019-07-25 23:25:59 +0200
committerKasper Timm Hansen <kaspth@gmail.com>2019-07-25 23:25:59 +0200
commit64a430129fbec2320054a8fc85672994f38a9ee0 (patch)
tree76abb6fbdf6265e4782a64b60679560e80daf447 /activesupport
parent579864f79ce1e7b9e4cae0518ddb65b5dd456b8c (diff)
downloadrails-64a430129fbec2320054a8fc85672994f38a9ee0.tar.gz
rails-64a430129fbec2320054a8fc85672994f38a9ee0.tar.bz2
rails-64a430129fbec2320054a8fc85672994f38a9ee0.zip
Use binding.local_variable_get for `:for`
Simplifies the surrounding code outside `convert_value`. Ref: https://github.com/rails/rails/pull/36758
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/hash_with_indifferent_access.rb8
1 files changed, 3 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/hash_with_indifferent_access.rb b/activesupport/lib/active_support/hash_with_indifferent_access.rb
index bbb7c36382..e1d233e208 100644
--- a/activesupport/lib/active_support/hash_with_indifferent_access.rb
+++ b/activesupport/lib/active_support/hash_with_indifferent_access.rb
@@ -367,17 +367,15 @@ module ActiveSupport
key.kind_of?(Symbol) ? key.to_s : key
end
- EMPTY_HASH = {}.freeze
-
- def convert_value(value, options = EMPTY_HASH) # :doc:
+ def convert_value(value, for: nil) # :doc:
if value.is_a? Hash
- if options[:for] == :to_hash
+ if binding.local_variable_get(:for) == :to_hash
value.to_hash
else
value.nested_under_indifferent_access
end
elsif value.is_a?(Array)
- if options[:for] != :assignment || value.frozen?
+ if binding.local_variable_get(:for) != :assignment || value.frozen?
value = value.dup
end
value.map! { |e| convert_value(e, options) }