From: David Flanagan Date: 2009-05-14T07:05:03+09:00 Subject: Re: Superclass of eigenclass On May 7, 9:21 am, Rick DeNatale wrote: > On Thu, May 7, 2009 at 11:50 AM, Rick DeNatale wrote: > > On Thu, May 7, 2009 at 8:35 AM, Danny O cuiv wrote: > >> On page 261 of The Ruby Programming Language, they state: > > >> "Class objects are special: they have superclasses. The eigenclasses of > >> class objects are also special: they have superclasses, too. The > >>eigenclassof an ordinary object stands alone and has nosuperclass." > > > I'm pretty sure that this is a typo. > > Just for the record, I just submitted the following erratum report to > the O'Reilly site for the book: Rick, It wasn't a typo, and it correctly describes how method inheritance works, but it doesn't reflect the reality of the superclass method of eigenclasses. Your suggested replacement text won't work as a replacement--the point of the paragraph in question is to explain method inheritance, not to get into the nitty gritty about eigenclasses. Having said that, I should perhaps try to fit some of these eigenclass details into my next edition, as well as your argument for why the term "singleton class" makes sense. David Flanagan > Page 261 2nd Paragraph: > The paragraph says: > > "Class objects are special: they have superclasses. The eigenclasses of > class objects are also special: they have superclasses, too. Theeigenclassof an ordinary object stands alone and has nosuperclass." > > Both theeigenclassof a class object and theeigenclassof an > ordinary object have asuperclass.  If not then sending a message to > an ordinary object would end up invoking method_missing. > > I think that the paragraph should read: > > "Class objects are special: they can have subclasses. The eigenclasses of > class objects are also special: they can have subclasses, too. Theeigenclassof an ordinary object can have neither a subclass, nor any > other instance except that single ordinary object.  If an ordinary > object with aneigenclassis duplicated with the Object#dup method, > the duplicate will not acquire any of it's singleton methods. If it is > cloned with the Object#clone method, the result will get aneigenclass > which is a duplicate of the original objectseigenclass, so that eacheigenclasshas but a single instance." > > The following ruby code (which behaves identically on Ruby 1.8.6, > 1.8.7 and 1.9.1) illustrates the above: > > module Kernel >   defeigenclass >     class << self;self;end >   end > end > > class TestClass > >   def bar >     :bar >   end > >   def self.foo >     :foo >   end > end > > t = TestClass.new > def t.gorp >   :gorp > end > > p t_eigenclass = t.eigenclass# => #> > p t_eigenclass.superclass# => # > > p t.bar # => :bar > p t.gorp # => :gorp > > p t_dup = t.dup > p t_clone = t.clone > p t_clone.respond_to?(:gorp) # => true > p t_clone.eigenclass== t_eigenclass # => false > p t_dup.respond_to?(:gorp) # => false > > p t.class.foo # => :foo > p t.eigenclass.foo # => :foo > > -- > Rick DeNatale > > Blog:http://talklikeaduck.denhaven2.com/ > Twitter:http://twitter.com/RickDeNatale > WWR:http://www.workingwithrails.com/person/9021-rick-denatale > LinkedIn:http://www.linkedin.com/in/rickdenatale