Browse files

Merge pull request #7194 from alexandrz/master

DRY class_attribute
  • Loading branch information...
2 parents 1f870a2 + d59208d commit 07ecaf5063c06558e0566f70cafdfdbe2b7ac2cb @carlosantoniodasilva carlosantoniodasilva committed Jul 29, 2012
Showing with 3 additions and 6 deletions.
  1. +3 −6 activesupport/lib/active_support/core_ext/class/attribute.rb
View
9 activesupport/lib/active_support/core_ext/class/attribute.rb
@@ -79,14 +79,12 @@ def self.#{name}?() !!#{name} end
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 @@ def #{name}
end
if instance_reader
- remove_possible_method :#{name}
- def #{name}
+ redefine_method(:#{name}) do
defined?(@#{name}) ? @#{name} : self.class.#{name}
end

0 comments on commit 07ecaf5

Please sign in to comment.