aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-07-02 17:47:56 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2013-07-02 17:47:56 -0700
commit127d16e0be9dc79c5c07359c101a2b2dfb1c9f03 (patch)
tree6ae543561ead277b0913196b69d78861a1092f73 /activerecord
parent7e6ea012d2a2fce872d01d2ce045a6f136a42ea4 (diff)
downloadrails-127d16e0be9dc79c5c07359c101a2b2dfb1c9f03.tar.gz
rails-127d16e0be9dc79c5c07359c101a2b2dfb1c9f03.tar.bz2
rails-127d16e0be9dc79c5c07359c101a2b2dfb1c9f03.zip
reduce the amount of code Ruby has to parse
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/attribute_methods/read.rb11
1 files changed, 8 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/read.rb b/activerecord/lib/active_record/attribute_methods/read.rb
index 8b3df3cd07..684fe2dc05 100644
--- a/activerecord/lib/active_record/attribute_methods/read.rb
+++ b/activerecord/lib/active_record/attribute_methods/read.rb
@@ -52,16 +52,21 @@ module ActiveRecord
# key the @attributes_cache in read_attribute.
def define_method_attribute(name)
safe_name = name.unpack('h*').first
+ temp_method = "__temp__#{safe_name}"
+
ActiveRecord::AttributeMethods::AttrNames.set_name_cache safe_name, name
generated_attribute_methods.module_eval <<-STR, __FILE__, __LINE__ + 1
- def __temp__#{safe_name}
+ def #{temp_method}
name = ::ActiveRecord::AttributeMethods::AttrNames::ATTR_#{safe_name}
read_attribute(name) { |n| missing_attribute(n, caller) }
end
- alias_method #{name.inspect}, :__temp__#{safe_name}
- undef_method :__temp__#{safe_name}
STR
+
+ generated_attribute_methods.module_eval do
+ alias_method name, temp_method
+ undef_method temp_method
+ end
end
private