From: Robert Klemme Date: 2005-02-11T00:40:07+09:00 Subject: Re: Class of the Instance [was Re: Building a Better Functor] "Gavin Kistner" schrieb im Newsbeitrag news:eee6f56d3405a57c4480046c35fca189@refinery.com... > On Feb 10, 2005, at 7:35 AM, Robert Klemme wrote: > > "Gavin Kistner" schrieb im Newsbeitrag > > news:991b24e67ac5d4902f4b04192210830a@refinery.com... > >>> Robert Klemme wrote: > >>>> class << self;self;end.class_eval do > >> Is it to add new methods to the instance only, and not all instances > >> derived from Foo? > > > > Exactly. > > Coming from Javascript (where every instance is trivially extensible > directly) that seems somewhat cumbersome. JavaScript has no classes as far as I know. Ruby has classes and from that alone it's obvious that it's a bit more complicated. Usually when you define instance methods you do obj = .... class < 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) Discussion - a lot, RCR - maybe. > about adding a simple method like that to the > language, so you can simply do: > > f = Foo.new > f.instance_class.class_eval{ ... } class Object def instance_class() class< ? > > 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. IMHO it's sufficient to have the simplified access to the singleton class. OTOH, it's not too difficult to obtain that, so... Regards robert