diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2007-04-16 22:17:59 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2007-04-16 22:17:59 +0000 |
commit | a0e78f7442143c1366de06ec28342ad728870a1c (patch) | |
tree | 08dcd02f5becce7f8b07acf93b99380e40d04f93 /activesupport/lib/active_support | |
parent | 7722e2bf6c8bc0e81e61a47809cdbbf52b33ce6b (diff) | |
download | rails-a0e78f7442143c1366de06ec28342ad728870a1c.tar.gz rails-a0e78f7442143c1366de06ec28342ad728870a1c.tar.bz2 rails-a0e78f7442143c1366de06ec28342ad728870a1c.zip |
Fixed that parameters from XML should also be presented in a hash with indifferent access [DHH] Hash#with_indifferent_access now also converts hashes kept in arrays to indifferent access (makes it easier to treat HTML and XML parameters the same) [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6532 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/core_ext/hash/conversions.rb | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/hash/indifferent_access.rb | 10 |
2 files changed, 10 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/core_ext/hash/conversions.rb b/activesupport/lib/active_support/core_ext/hash/conversions.rb index bbfc2502a1..07d50df6ba 100644 --- a/activesupport/lib/active_support/core_ext/hash/conversions.rb +++ b/activesupport/lib/active_support/core_ext/hash/conversions.rb @@ -111,7 +111,7 @@ module ActiveSupport #:nodoc: 'forcecontent' => true, 'keeproot' => true, 'contentkey' => '__content__') - )) + )) end def create_from_xml(xml) diff --git a/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb b/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb index 6c7e6d76ac..01d5b3a6a3 100644 --- a/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb +++ b/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb @@ -73,8 +73,16 @@ class HashWithIndifferentAccess < Hash def convert_key(key) key.kind_of?(Symbol) ? key.to_s : key end + def convert_value(value) - value.is_a?(Hash) ? value.with_indifferent_access : value + case value + when Hash + value.with_indifferent_access + when Array + value.collect { |e| e.is_a?(Hash) ? e.with_indifferent_access : e } + else + value + end end end |