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, line 35
def singleton_class
  class << self; self; end
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, line 80
def singleton_class?
  singleton_object
  true
rescue ::TypeError
  false
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, line 50
def singleton_object
  [true, false, nil].each { |obj|
    return obj if self.equal?(obj.singleton_class)
  }

  # raises TypeError if neither class nor module
  ::ObjectSpace.each_object(self) { |obj|
    return obj if self.equal?(obj.singleton_class)
  }

  # if we got here, it can't be a singleton class
  # or its singleton object doesn't exist anymore
  raise ::TypeError
rescue ::TypeError
  raise ::TypeError, 'not a singleton class'
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