From: Rick DeNatale Date: 2009-05-08T01:21:41+09:00 Subject: Re: Superclass of eigenclass 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 >> eigenclass of an ordinary object stands alone and has no superclass." > > 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: 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. The eigenclass of an ordinary object stands alone and has no superclass." Both the eigenclass of a class object and the eigenclass of an ordinary object have a superclass. 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. The eigenclass of an ordinary object can have neither a subclass, nor any other instance except that single ordinary object. If an ordinary object with an eigenclass is 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 an eigenclass which is a duplicate of the original objects eigenclass, so that each eigenclass has 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 def eigenclass 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