diff options
author | José Valim <jose.valim@gmail.com> | 2011-05-17 05:33:48 -0700 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-05-17 05:33:48 -0700 |
commit | ab9639f945b1f5de40b2889ce47953dad645bdf5 (patch) | |
tree | 28787518a66a2ab116d98edad3c56e7605391083 /activesupport/lib | |
parent | a52dc0d9cc452aa97b5bf69039b5f2b28fb128d9 (diff) | |
parent | 94617d7da1e76daeae3a05c61b42321163f93d62 (diff) | |
download | rails-ab9639f945b1f5de40b2889ce47953dad645bdf5.tar.gz rails-ab9639f945b1f5de40b2889ce47953dad645bdf5.tar.bz2 rails-ab9639f945b1f5de40b2889ce47953dad645bdf5.zip |
Merge pull request #1099 from dlee/optimize_indifferent_access
Optimize parts of HashWithIndifferentAccess
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/hash_with_indifferent_access.rb | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/hash_with_indifferent_access.rb b/activesupport/lib/active_support/hash_with_indifferent_access.rb index 8ec4f6e09a..39ebc1ec82 100644 --- a/activesupport/lib/active_support/hash_with_indifferent_access.rb +++ b/activesupport/lib/active_support/hash_with_indifferent_access.rb @@ -10,6 +10,10 @@ module ActiveSupport true end + def with_indifferent_access + self + end + def initialize(constructor = {}) if constructor.is_a?(Hash) super() @@ -58,8 +62,12 @@ module ActiveSupport # hash_1.update(hash_2) # => {"key"=>"New Value!"} # def update(other_hash) - other_hash.each_pair { |key, value| regular_writer(convert_key(key), convert_value(value)) } - self + if other_hash.is_a? HashWithIndifferentAccess + super(other_hash) + else + other_hash.each_pair { |key, value| regular_writer(convert_key(key), convert_value(value)) } + self + end end alias_method :merge!, :update |