Ufuk Kayserilioglu @ufuk.dev · Jan 27

Noel, the explanation for how singleton classes are represented in Ruby isn't correct. There is no separate `singleton_class` storage, even though Ruby API makes it look like that. What really is the internal class of the object points to the superclass which has the original class as its own class.

11 likes 2 replies

?

Replies

Oğulcan Girginç · Jan 28

I feel like this is a perfect time to pitch “Ruby Under Microscope V2” by Noel & Ufuk 😅

Ufuk Kayserilioglu · Jan 27

The benefit of doing this is that you don't need a separate lookup for methods, you just look up the inheritance chain. Since the singleton class is IN the inheritance chain, it just works. However, Ruby hides this internal implementation detail from you by still returning the original superclass.