From: ptkwt@... (Phil Tomson) Date: 2005-02-11T00:40:07+09:00 Subject: Re: Class of the Instance [was Re: Building a Better Functor] In article , Gavin Kistner wrote: >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. > >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{ ... } >? > >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. > Isn't this the common way of doing this: f = Foo.new def f.somemethod "in somemethod" end f.somemethod #=> "in somemethod" Phil