diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-06-29 15:31:35 -0600 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-06-29 15:31:35 -0600 |
commit | 972d9be34c4900b9ba2840e05931509fe521c06d (patch) | |
tree | 06cbd832930bdd2e3e84c4894a31412d3351cfeb /activerecord/lib | |
parent | f123da507a703c3177c26a4f59cab53d81f4fa7c (diff) | |
download | rails-972d9be34c4900b9ba2840e05931509fe521c06d.tar.gz rails-972d9be34c4900b9ba2840e05931509fe521c06d.tar.bz2 rails-972d9be34c4900b9ba2840e05931509fe521c06d.zip |
Use `Hash#transform_values` to clean up `AttributeSet`
Diffstat (limited to 'activerecord/lib')
-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' |