4 ms·
Every Ruby object is an instance of a singleton class that inherits from its declared class. # o is an instance of its singleton class, # which inherit
by wycats 15y ago
Every Ruby object is an instance of a singleton class that inherits from its declared class.
# o is an instance of its singleton class,
# which inherits from Object
o = Object.new
It is like saying:
class Object
def self.new(*args, &block)
# Class.new(Object) creates an anonymous
# subclass of Object
Class.new(Object).new(*args, &block)
end
end
except with built-in language support. Instead of having to do this manually, every object gets a singleton.