From: "David A. Black" Date: 2005-02-11T01:26:55+09:00 Subject: Re: Class of the Instance [was Re: Building a Better Functor] Hi -- On Thu, 10 Feb 2005, Gavin Kistner wrote: > Coming from Javascript (where every instance is trivially extensible Aw, come from Ruby already! :-) > directly) that seems somewhat cumbersome. Whoops, I snipped the part you were talking about... but aren't they in Ruby too? o = Object.new def o.x; puts "I'm a new method!"; end > Do many people write things like: > > class Object > def instance_class > class< end > end > > in a common library they re-use frequently? Is there an RCR (or has there > been discussion) about adding a simple method like that to the language, so > you can simply do: > > f = Foo.new > f.instance_class.class_eval{ ... } Yes; I submitted such an RCR, for Kernel#singleton_class. (I know about the naming issues, but I'd rather not deviate from what Matz uses at a given time.) See http://www.rcrchive.net/rcr/show/231 > Or (what I'm really looking for) perhaps it might be nice to have a > define_method method that worked directly for instances. Hrm, but what would > the syntax be? Perhaps that's not such a good idea. I think that Kernel#singleton_class would work for that purpose, and would also completely transform people's understanding of the whole class/singleton-class duality. David -- David A. Black dblack@wobblini.net