aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/class/attribute.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2012-07-30 08:19:15 +0200
committerJosé Valim <jose.valim@gmail.com>2012-07-30 08:19:15 +0200
commit8601f733af3311e3b0ebb1f517432593c9b0fedd (patch)
treebf5e87b9a0f783f949887008728c56e2565830a3 /activesupport/lib/active_support/core_ext/class/attribute.rb
parent69f62ecaff66c25b62c5d9cad41c62fc74d717c5 (diff)
downloadrails-8601f733af3311e3b0ebb1f517432593c9b0fedd.tar.gz
rails-8601f733af3311e3b0ebb1f517432593c9b0fedd.tar.bz2
rails-8601f733af3311e3b0ebb1f517432593c9b0fedd.zip
Revert "DRY class_attribute code"
class_attribute is a building block and using define_method can be much slower for such basic method definitions. This reverts commit d59208d7032e2be855a89ad8d4685cc08dd7cdb3.
Diffstat (limited to 'activesupport/lib/active_support/core_ext/class/attribute.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/class/attribute.rb9
1 files changed, 6 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/core_ext/class/attribute.rb b/activesupport/lib/active_support/core_ext/class/attribute.rb
index da0a12136c..7b6f8ab0a1 100644
--- a/activesupport/lib/active_support/core_ext/class/attribute.rb
+++ b/activesupport/lib/active_support/core_ext/class/attribute.rb
@@ -79,12 +79,14 @@ class Class
def self.#{name}=(val)
singleton_class.class_eval do
- redefine_method(:#{name}) { val }
+ remove_possible_method(:#{name})
+ define_method(:#{name}) { val }
end
if singleton_class?
class_eval do
- redefine_method(:#{name}) do
+ remove_possible_method(:#{name})
+ def #{name}
defined?(@#{name}) ? @#{name} : singleton_class.#{name}
end
end
@@ -93,7 +95,8 @@ class Class
end
if instance_reader
- redefine_method(:#{name}) do
+ remove_possible_method :#{name}
+ def #{name}
defined?(@#{name}) ? @#{name} : self.class.#{name}
end