From: Gavin Kistner Date: 2005-02-10T23:57:22+09:00 Subject: Re: Class of the Instance [was Re: Building a Better Functor] On Feb 10, 2005, at 7:47 AM, Gavin Kistner wrote: > 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. Well, no, maybe it would be nice. Something like: class Object def add_method( name, &block ) case self when Class self.class_eval{ define_method( name, &block ) } else class< # says 'whee' f1.yow #=> # says 'yow!' f2.add_method( 'booya!' ){ puts "#{self} says 'booya!'" } f2.booya! #=> # says 'booya!' f1.booya! #=> tmp.rb:33: undefined method `booya!' for # (NoMethodError) I'm certainly adding that to my personal library, but it seems like it would be a nice (useful, good, less-hacks-needed) built-in. -- (-, /\ \/ / /\/