diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-06-21 13:09:48 -0600 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-06-21 13:09:48 -0600 |
commit | 3e422e201de47c6158d2f60679604e51d2539dfb (patch) | |
tree | 7dc0dfe2c8687876e7dd4a4250279d2c502cee65 /activerecord/lib | |
parent | 0e9a7059664eb9dee8e3afae60d26ff858d0d84b (diff) | |
download | rails-3e422e201de47c6158d2f60679604e51d2539dfb.tar.gz rails-3e422e201de47c6158d2f60679604e51d2539dfb.tar.bz2 rails-3e422e201de47c6158d2f60679604e51d2539dfb.zip |
Move `attributes` to the `AttributeSet` object.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/attribute_methods.rb | 4 | ||||
-rw-r--r-- | activerecord/lib/active_record/attribute_set.rb | 5 |
2 files changed, 6 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb index 268cec6160..267377cec6 100644 --- a/activerecord/lib/active_record/attribute_methods.rb +++ b/activerecord/lib/active_record/attribute_methods.rb @@ -271,9 +271,7 @@ module ActiveRecord # person.attributes # # => {"id"=>3, "created_at"=>Sun, 21 Oct 2012 04:53:04, "updated_at"=>Sun, 21 Oct 2012 04:53:04, "name"=>"Francesco", "age"=>22} def attributes - attribute_names.each_with_object({}) { |name, attrs| - attrs[name] = read_attribute(name) - } + @attributes.to_hash end # Returns an <tt>#inspect</tt>-like string for the value of the diff --git a/activerecord/lib/active_record/attribute_set.rb b/activerecord/lib/active_record/attribute_set.rb index 102ef17e16..39f4ffe628 100644 --- a/activerecord/lib/active_record/attribute_set.rb +++ b/activerecord/lib/active_record/attribute_set.rb @@ -10,6 +10,11 @@ module ActiveRecord attributes.update(other.attributes) end + def to_hash + attributes.each_with_object({}) { |(k, v), h| h[k] = v.value } + end + alias_method :to_h, :to_hash + def freeze @attributes.freeze super |