From d59208d7032e2be855a89ad8d4685cc08dd7cdb3 Mon Sep 17 00:00:00 2001 From: Aleksandr Zykov Date: Sun, 29 Jul 2012 22:33:39 +0600 Subject: DRY class_attribute code --- activesupport/lib/active_support/core_ext/class/attribute.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/class/attribute.rb b/activesupport/lib/active_support/core_ext/class/attribute.rb index 7b6f8ab0a1..da0a12136c 100644 --- a/activesupport/lib/active_support/core_ext/class/attribute.rb +++ b/activesupport/lib/active_support/core_ext/class/attribute.rb @@ -79,14 +79,12 @@ class Class def self.#{name}=(val) singleton_class.class_eval do - remove_possible_method(:#{name}) - define_method(:#{name}) { val } + redefine_method(:#{name}) { val } end if singleton_class? class_eval do - remove_possible_method(:#{name}) - def #{name} + redefine_method(:#{name}) do defined?(@#{name}) ? @#{name} : singleton_class.#{name} end end @@ -95,8 +93,7 @@ class Class end if instance_reader - remove_possible_method :#{name} - def #{name} + redefine_method(:#{name}) do defined?(@#{name}) ? @#{name} : self.class.#{name} end -- cgit v1.2.3