aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/hash_with_indifferent_access.rb
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2013-05-14 12:39:48 -0700
committerRafael Mendonça França <rafaelmfranca@gmail.com>2013-05-14 12:39:48 -0700
commitc7182563e59c7d32105211f3dfb0bcb6db74ab85 (patch)
treeca729508d736eeef104bded6af7fa6d721863ffe /activesupport/lib/active_support/hash_with_indifferent_access.rb
parente8e7d8357c5f641842f5c4730396fae4d423723a (diff)
parentdf24b8790f22384a068fece7042f04ffd2fcb33e (diff)
downloadrails-c7182563e59c7d32105211f3dfb0bcb6db74ab85.tar.gz
rails-c7182563e59c7d32105211f3dfb0bcb6db74ab85.tar.bz2
rails-c7182563e59c7d32105211f3dfb0bcb6db74ab85.zip
Merge pull request #10266 from vipulnsward/fix_HIA_to_hash
fix HashWithIndifferentAccess#to_hash behaviour
Diffstat (limited to 'activesupport/lib/active_support/hash_with_indifferent_access.rb')
-rw-r--r--activesupport/lib/active_support/hash_with_indifferent_access.rb10
1 files changed, 7 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/hash_with_indifferent_access.rb b/activesupport/lib/active_support/hash_with_indifferent_access.rb
index 1b20592e4c..9a9ed02bd9 100644
--- a/activesupport/lib/active_support/hash_with_indifferent_access.rb
+++ b/activesupport/lib/active_support/hash_with_indifferent_access.rb
@@ -229,7 +229,11 @@ module ActiveSupport
# Convert to a regular hash with string keys.
def to_hash
- Hash.new(default).merge!(self)
+ _new_hash= {}
+ each do |key, value|
+ _new_hash[convert_key(key)] = convert_value(value,true)
+ end
+ Hash.new(default).merge!(_new_hash)
end
protected
@@ -237,9 +241,9 @@ module ActiveSupport
key.kind_of?(Symbol) ? key.to_s : key
end
- def convert_value(value)
+ def convert_value(value, _convert_for_to_hash = false)
if value.is_a? Hash
- value.nested_under_indifferent_access
+ _convert_for_to_hash ? value.to_hash : value.nested_under_indifferent_access
elsif value.is_a?(Array)
value = value.dup if value.frozen?
value.map! { |e| convert_value(e) }