aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/attribute_methods
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2015-08-31 11:54:43 -0600
committerSean Griffin <sean@thoughtbot.com>2015-08-31 11:56:17 -0600
commit9f1b5c9b4032d081f5b7d7fe9697ba24e2ae3ff8 (patch)
tree7bd6b81d2da751f0ab8a7f54e7eb1bcd9fb7bbd9 /activerecord/lib/active_record/attribute_methods
parenta03f7e8d602cb7425976714a651da93c2ac08f06 (diff)
downloadrails-9f1b5c9b4032d081f5b7d7fe9697ba24e2ae3ff8.tar.gz
rails-9f1b5c9b4032d081f5b7d7fe9697ba24e2ae3ff8.tar.bz2
rails-9f1b5c9b4032d081f5b7d7fe9697ba24e2ae3ff8.zip
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.
Diffstat (limited to 'activerecord/lib/active_record/attribute_methods')
-rw-r--r--activerecord/lib/active_record/attribute_methods/read.rb4
1 files changed, 1 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/read.rb b/activerecord/lib/active_record/attribute_methods/read.rb
index 2363cf7608..5197e21fa4 100644
--- a/activerecord/lib/active_record/attribute_methods/read.rb
+++ b/activerecord/lib/active_record/attribute_methods/read.rb
@@ -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