From 9f1b5c9b4032d081f5b7d7fe9697ba24e2ae3ff8 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Mon, 31 Aug 2015 11:54:43 -0600 Subject: [PATCH] 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. --- activerecord/lib/active_record/attribute_methods/read.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/activerecord/lib/active_record/attribute_methods/read.rb b/activerecord/lib/active_record/attribute_methods/read.rb index 2363cf7608757..5197e21fa4408 100644 --- a/activerecord/lib/active_record/attribute_methods/read.rb +++ b/activerecord/lib/active_record/attribute_methods/read.rb @@ -56,14 +56,12 @@ def #{temp_method} end end - ID = 'id'.freeze - # Returns the value of the attribute identified by attr_name 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