From 64a430129fbec2320054a8fc85672994f38a9ee0 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Thu, 25 Jul 2019 23:25:59 +0200 Subject: Use binding.local_variable_get for `:for` Simplifies the surrounding code outside `convert_value`. Ref: https://github.com/rails/rails/pull/36758 --- activesupport/lib/active_support/hash_with_indifferent_access.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'activesupport') 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) } -- cgit v1.2.3