From: "David A. Black" Date: 2004-03-08T09:34:40+09:00 Subject: Re: proposal: class< On Mon, 08 Mar 2004 08:35:34 +0900, Yukihiro Matsumoto wrote: > > In message "proposal: class< > on 04/03/08, Simon Strandgaard writes: > > > > |'obj.extend' and 'class< > |However there is a difference.. 'class< > |invoke #extend_object, and #extended. To me it feels > > |inconsistent that there is no way to execute code on the > > |point when the extension occurs. > > > > 'obj.extend' add a module to the inheritance graph (per object base), > > whereas 'class < > singleton class. Virtually, singleton class always exists for each > > object, never added, never extended. > > > > I don't get this.. (thanks+sorry matz). > > I had the impression that they didn't differ much. > Is there anyone which can explain this to me? When you do "obj.extend(Mod)", obj.ancestors changes (new module added). When you do "class << obj ... end", obj.ancestors stays the same. All you're doing is adding a method to a class; you're not extending obj, in the sense of putting a new module in its ancestry (i.e., method lookup path). If you invoked #extended every time you did this, you'd have to invoke it on every String object if you did: class String #... end Singleton classes are, I think, implemented in such a way that they don't actually have existence until they're first referred to. But, as Matz says, every object virtually has a singleton class all the time. David -- David A. Black dblack@wobblini.net