diff options
author | Godfrey Chan <godfreykfc@gmail.com> | 2014-06-29 14:32:46 -0700 |
---|---|---|
committer | Godfrey Chan <godfreykfc@gmail.com> | 2014-06-29 14:32:46 -0700 |
commit | d9827ca49fdfc4f1771a3644e737dd67e2e168c3 (patch) | |
tree | ce4f9edb613c9868e1ee4a31778594b69759ea17 | |
parent | a607fd27e11f9d3545862dcbaac1a59deac9236c (diff) | |
parent | 972d9be34c4900b9ba2840e05931509fe521c06d (diff) | |
download | rails-d9827ca49fdfc4f1771a3644e737dd67e2e168c3.tar.gz rails-d9827ca49fdfc4f1771a3644e737dd67e2e168c3.tar.bz2 rails-d9827ca49fdfc4f1771a3644e737dd67e2e168c3.zip |
Merge pull request #15982 from sgrif/sg-attr-set-map-values
Use `Hash#transform_values` to clean up `AttributeSet`
-rw-r--r-- | activerecord/lib/active_record/attribute_set.rb | 10 | ||||
-rw-r--r-- | activerecord/lib/active_record/base.rb | 1 |
2 files changed, 4 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/attribute_set.rb b/activerecord/lib/active_record/attribute_set.rb index 5be11e6ab9..8a964fb03c 100644 --- a/activerecord/lib/active_record/attribute_set.rb +++ b/activerecord/lib/active_record/attribute_set.rb @@ -13,11 +13,11 @@ module ActiveRecord end def values_before_type_cast - attributes.each_with_object({}) { |(k, v), h| h[k] = v.value_before_type_cast } + attributes.transform_values(&:value_before_type_cast) end def to_hash - initialized_attributes.each_with_object({}) { |(k, v), h| h[k] = v.value } + initialized_attributes.transform_values(&:value) end alias_method :to_h, :to_hash @@ -43,11 +43,7 @@ module ActiveRecord end def initialize_dup(_) - @attributes = attributes.dup - attributes.each do |key, attr| - attributes[key] = attr.dup - end - + @attributes = attributes.transform_values(&:dup) super end diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 662c99269e..32e7c50588 100644 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -9,6 +9,7 @@ require 'active_support/core_ext/class/delegating_attributes' require 'active_support/core_ext/array/extract_options' require 'active_support/core_ext/hash/deep_merge' require 'active_support/core_ext/hash/slice' +require 'active_support/core_ext/hash/transform_values' require 'active_support/core_ext/string/behavior' require 'active_support/core_ext/kernel/singleton_class' require 'active_support/core_ext/module/introspection' |