Permalink
Browse files

use the key name yielded to the fetch block

  • Loading branch information...
1 parent 69e84e1 commit 857bd732723a6ca297195198b9796ba79226f83f @tenderlove tenderlove committed Feb 8, 2012
Showing with 7 additions and 9 deletions.
  1. +7 −9 activerecord/lib/active_record/attribute_methods/read.rb
@@ -120,22 +120,20 @@ def instance_cast_method(attr_name)
# "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

0 comments on commit 857bd73

Please sign in to comment.