module Nuggets::Object::SingletonClassMixin

Public Instance Methods

eigenclass()
Alias for: singleton_class
eigenclass?()
Alias for: singleton_class?
eigenobject()
Alias for: singleton_object
ghost_class()
Alias for: singleton_class
ghost_class?()
Alias for: singleton_class?
ghost_object()
Alias for: singleton_object
metaclass()
Alias for: singleton_class
metaclass?()
Alias for: singleton_class?
metaobject()
Alias for: singleton_object
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_instance()
Alias for: singleton_object
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
uniclass()
Alias for: singleton_class
uniclass?()
Alias for: singleton_class?
uniobject()
Alias for: singleton_object
virtual_class()
Alias for: singleton_class
virtual_class?()
Alias for: singleton_class?
virtual_object()
Alias for: singleton_object