Skip to content

Commit

Permalink
Inline uneccessary frozen string constant
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sgrif committed Aug 31, 2015
1 parent a03f7e8 commit 9f1b5c9
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions activerecord/lib/active_record/attribute_methods/read.rb
Expand Up @@ -56,14 +56,12 @@ 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'.freeze
_read_attribute(name, &block)
end

Expand Down

0 comments on commit 9f1b5c9

Please sign in to comment.