mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Further simplify singleton_class checking in class_attribute
This commit is contained in:
committed by
Aaron Patterson
parent
40cab62560
commit
520918aad9
@@ -81,21 +81,13 @@ class Class
|
||||
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}?
|
||||
@@ -107,9 +99,4 @@ class Class
|
||||
attr_writer name if instance_writer
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def singleton_class?
|
||||
!name || '' == name
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user