From: Kedar Mhaswade Date: 2013-03-14T23:14:13+09:00 Subject: Re: Understanding Ruby Classes, Objects and Methods. Robert Klemme wrote in post #1101602: > On Thu, Mar 14, 2013 at 2:42 PM, Kedar Mhaswade > wrote: >> And do you suggest that that statement is "not true"? > Yes, see above. It's at least imprecise since "abc" does not reference > a single instance of String but it will produce a new instance every > time it is executed. See the part of my previous mail you did not > quote. OK. Clarified. Thank you. > >>> anonymous class - solely because it "seems right"? Why does it "seem >> be the original superclass of Example. It then references the module >> from this new class object in such a way that when you look a method up >> in this class, it actually looks it up in the module, as shown in Figure >> 24.5, on the next page. >> ---------------------------------------------------------------- >> >> Is this not right? > > I don't know. But I do know that this is an implementation detail of > MRI which is invisible to the user of the language. Other than > singleton classes these new class objects cannot in any way be > observed by Ruby programs: > > irb(main):001:0> a = Object.superclass.object_id > => -1073527798 > irb(main):002:0> module X end > => nil > irb(main):003:0> class Object > irb(main):004:1> include X > irb(main):005:1> end > => Object > irb(main):006:0> b = Object.superclass.object_id > => -1073527798 > irb(main):007:0> a == b > => true > > The information may be right or outdated but it does not necessarily > help users of the language to understand how Ruby works. > My observation too has been that this so-called anonymous class is not to be found via the :superclass method and I have already clarified that in the document as: ------------------------------------------------------------------- This diagram is not entirely accurate because although Anonclass appears to become superclass of Someclass, just by the virtue of inclusion of module Mod, Anonclass is not returned when you do Someclass.superclass. ------------------------------------------------------------------- But if methods were only to be defined on class objects, I am not sure where the included module methods would come from without disturbing inheritance chain of classes. Any MRI experts -- how does it _really_ happen? And how about JRuby/Rubinius? -- Posted via http://www.ruby-forum.com/.