From: Ben Tompkins Date: 2007-09-03T02:26:03+09:00 Subject: Re: Shouldn't it be class >> self , or am I dyslexic? I like it when people agree with me, and according to the diagram on page 384 of Programming Ruby, you are basically correct to say that "self inherits from the singleton class." The diagram shows that a "virtual" (singleton) class is inserted into the inheritance hierarchy for self (or whatever the RHS happens to be) as an immediate subclass of the most derived, non-singleton, class of which the RHS is an instance whenever 'class << RHS ...' is executed. So even if we think of the '<<' as an "inheritance operator," it is still pointing in the wrong direction! But is inheritance really the right concept here? Notice that the singleton class is inserted below the most specific class of the RHS term. If the RHS were the same as its class (which is impossible), then Marcin would be right, because the singleton class would be subclassing the RHS. But no instance is ever the same as its class. What is really going on is that we are augmenting the interface of the RHS by decorating its most derived class with an anonymous class to which RHS has exclusive access, thus effectively adding the methods of the singleton class to the RHS. As the recipient of these new methods, RHS is on the receiving side of the operation, which is why 'class >> RHS ...' is more intuitive than 'class << RHS ... .' Sebastian Hungerecker wrote: > Marcin Miel��y��ski wrote: > >> >> What this does ? it either creates and opens singleton class for s >> instance or reopens the singleton it if it already exits. Since >> singleton classes dont have their names you could also imagine >> between class and << tokens here. > > Yes, but there is a major difference between those two. In the former > case A > inherits from B, but in the latter case the singleton class does *not* > inherit from self, self inherits from the singleton class (well actually > self > is an instance of the singleton class, but the point is that self is > based on > the class and not the other way around), so Ben has a point when he > says, > that the arrows should point in the other direction. -- Posted via http://www.ruby-forum.com/.