Adding the following code to an object is supposed to allow me to retrieve the singleton class of any object.
class Object
def singleton_class
class << self; self; end
end
end
I had a Powerball class, which I instantiated this way
puts Powerball.new.singleton_class
puts Powerball.new.singleton_class
puts Powerball.singleton_class
puts Powerball.singleton_class
It gave me this output
#<Class:#<Powerball:0x007fd333040548>>
#<Class:#<Powerball:0x007fd333040408>>
#<Class:Powerball>
#<Class:Powerball>
So, the two instances of the powerball class have unique ids, while calling singleton_class directly on the class doesn't yield an object id.
Questions
Are the ids unique because each instance has a singleton class?
I understand that
self
within a class just returns the Class i.e. Class:Powerball, but since a class is an object, shouldn't it also have an id? Is there a way to access that id?