Skip to content

Commit

Permalink
Further simplify singleton_class checking in class_attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
bensie authored and tenderlove committed Dec 28, 2011
1 parent 40cab62 commit 520918a
Showing 1 changed file with 1 addition and 14 deletions.
15 changes: 1 addition & 14 deletions activesupport/lib/active_support/core_ext/class/attribute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,13 @@ def self.#{name}=(val)
define_method(:#{name}) { val }
end
if singleton_class?
class_eval do
remove_possible_method(:#{name})
def #{name}
defined?(@#{name}) ? @#{name} : singleton_class.#{name}
end
end
end
val
end
if instance_reader
remove_possible_method :#{name}
def #{name}
defined?(@#{name}) ? @#{name} : self.class.#{name}
defined?(@#{name}) ? @#{name} : singleton_class.#{name}
end
def #{name}?
Expand All @@ -107,9 +99,4 @@ def #{name}?
attr_writer name if instance_writer
end
end

private
def singleton_class?
!name || '' == name
end
end

0 comments on commit 520918a

Please sign in to comment.