PERF: stop allocating the string "id" over and over

This commit is contained in:
Sam 2014-11-18 21:38:27 +11:00
parent eb26f24bde
commit 9aa2b2d7bf

@ -76,12 +76,14 @@ def #{temp_method}
end
end
ID = 'id'.freeze
# Returns the value of the attribute identified by <tt>attr_name</tt> after
# it has been typecast (for example, "2004-12-12" in a date column is cast
# to a date object, like Date.new(2004, 12, 12)).
def read_attribute(attr_name, &block)
name = attr_name.to_s
name = self.class.primary_key if name == 'id'
name = self.class.primary_key if name == ID
@attributes.fetch_value(name, &block)
end