1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Use Hash#transform_values to clean up AttributeSet

This commit is contained in:
Sean Griffin 2014-06-29 15:31:35 -06:00
parent f123da507a
commit 972d9be34c
2 changed files with 4 additions and 7 deletions

View file

@ -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

View file

@ -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'