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

Inline uneccessary frozen string constant

We are only supporting Ruby 2.2 and later in Rails 5, so we do not need
an actual constant here. Additionally, referencing a constant actually
does a hash lookup (because constants are not constant in Ruby >_>).
This will be marginally (likely immeasurable) faster. It is less ugly.
This commit is contained in:
Sean Griffin 2015-08-31 11:54:43 -06:00
parent a03f7e8d60
commit 9f1b5c9b40

View file

@ -56,14 +56,12 @@ module ActiveRecord
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'.freeze
_read_attribute(name, &block)
end