Singleton classes of singleton classes of singleton classes...
So I've decided that I want to learn ruby. I didn't want to read a book that teaches you the basics, because I already know the basics of programming. So I've started to read Metaprogramming Ruby 2. It's a really cool book. Ruby is a pretty neat language. I think I do understand the object model but I do not quite understand something about singleton classes:
-
every object is an instance of a class
-
classes are objects
-
every object's "real class" is a singleton class specific to that object
-
the class of a singleton class is Class
-
but of course since singleton classes are classes and classes are objects the "real class" of a singleton class is a singleton class specific to that singleton class
-
so a object has a singleton class has a singleton class has a singleton class has...
-
that's an infinite number of objects and objects need memory so we need an infinite amount of memory and memory is made out of matter and the matter in the universe is limited...
So yeah: is ruby violating the laws of physics with its awesomeness, did I misunderstand the object model or is this somehow lazily evaluated?
Posted Aug 8, 2017, 9:57 AM UTC
They're allocated lazily.
Thanks for your answer!