module Nuggets::Object::SingletonClassMixin
Public Instance Methods
singleton_class → aClass
click to toggle source
Returns the singleton (or virtual/eigen/meta) class associated with object.
# File lib/nuggets/object/singleton_class_mixin.rb 35 def singleton_class 36 class << self; self; end 37 end
singleton_class? → +true+ or +false+
click to toggle source
Returns true
if object is a singleton_class
(i.e., has a singleton_object
), false
otherwise.
# File lib/nuggets/object/singleton_class_mixin.rb 80 def singleton_class? 81 singleton_object 82 true 83 rescue ::TypeError 84 false 85 end
singleton_object → anObject
click to toggle source
Returns the object of which object is the singleton_class. Raises a TypeError if object is not a singleton class.
# File lib/nuggets/object/singleton_class_mixin.rb 50 def singleton_object 51 [true, false, nil].each { |obj| 52 return obj if self.equal?(obj.singleton_class) 53 } 54 55 # raises TypeError if neither class nor module 56 ::ObjectSpace.each_object(self) { |obj| 57 return obj if self.equal?(obj.singleton_class) 58 } 59 60 # if we got here, it can't be a singleton class 61 # or its singleton object doesn't exist anymore 62 raise ::TypeError 63 rescue ::TypeError 64 raise ::TypeError, 'not a singleton class' 65 end
Also aliased as: virtual_object, ghost_object, eigenobject, metaobject, uniobject, singleton_instance