To clarify and fix what I wrote in the comments regarding how Ruby hides / expands eigenclasses, here is:
Ruby 1.8:
(1) The Object#class method always returns the first real (not eigenclass or iclass) superclass of the corresponding object class. eg,
o = Object.new class << o; end o.class
In other words, the Object#class method will never return eigenclass, it will go through them and instead return the first βrealβ class that it finds in the inheritance hierarchy.
(2) The Class#superclass has two cases. If the receiver is not eigenclass, it simply returns a superclass. However, if the receiver is eigenclass, this method returns the actual (not necessarily real) receiver class.
# case where receiver is a normal class (ie not an eigenclass) Module.superclass
At the top, Class#superclass behaves as expected in the case of a normal class, but for the eigenclass example it is indicated that the superclass of the module eigenclass class is a class that is not true. From this diagram, http://banisterfiend.wordpress.com/2008/10/25/the-secret-life-of-singletons/ we know that the superclass of the Eigenclass class is actually an Object. I'm not sure why Ruby 1.8 has this weird behavior.
Ruby 1.9:
(1) The Object#class method behaves the same with version 1.8.
(2) The Class#superclass no longer has two cases, it now treats eigenclass as it does with normal classes and returns the actual superclass as expected.
eg
class << Module; superclass; end
horseyguy
source share