aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-02-08 15:16:07 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2012-02-08 15:16:07 -0800
commit857bd732723a6ca297195198b9796ba79226f83f (patch)
tree3e9013782026a9cd9acd1f110d24ccfbe5f19338 /activerecord
parent69e84e10ec5b92de932ad0dc3497362f45a27edc (diff)
downloadrails-857bd732723a6ca297195198b9796ba79226f83f.tar.gz
rails-857bd732723a6ca297195198b9796ba79226f83f.tar.bz2
rails-857bd732723a6ca297195198b9796ba79226f83f.zip
use the key name yielded to the fetch block
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/attribute_methods/read.rb16
1 files changed, 7 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/read.rb b/activerecord/lib/active_record/attribute_methods/read.rb
index eff69cf174..53014e9e58 100644
--- a/activerecord/lib/active_record/attribute_methods/read.rb
+++ b/activerecord/lib/active_record/attribute_methods/read.rb
@@ -120,22 +120,20 @@ module ActiveRecord
# "2004-12-12" in a data column is cast to a date object, like Date.new(2004, 12, 12)).
def read_attribute(attr_name)
# If it's cached, just return it
- @attributes_cache.fetch(attr_name) {
-
- column = @columns_hash.fetch(attr_name) {
- return self.class.type_cast_attribute(attr_name, @attributes, @attributes_cache)
+ @attributes_cache.fetch(attr_name) { |name|
+ column = @columns_hash.fetch(name) {
+ return self.class.type_cast_attribute(name, @attributes, @attributes_cache)
}
- value = @attributes.fetch(attr_name) {
- return block_given? ? yield(attr_name) : nil
+ value = @attributes.fetch(name) {
+ return block_given? ? yield(name) : nil
}
- if self.class.cache_attribute?(attr_name)
- @attributes_cache[attr_name] ||= column.type_cast(value)
+ if self.class.cache_attribute?(name)
+ @attributes_cache[name] = column.type_cast(value)
else
column.type_cast value
end
-
}
end