From: Robert Klemme Date: 2005-01-26T19:15:47+09:00 Subject: Re: Injecting methods from one class into another. "George Moschovitis" schrieb im Newsbeitrag news:1106684784.267315.189500@z14g2000cwz.googlegroups.com... > > Hm, maybe for caching: > > @cached = lengthy_process_that_returns_an_unbound_method() > > ... > > Dunno whether that's more efficient than just remembering the symbol > and > > invoking the method via send... > > Robert, > > thank you for taking the time to answer my post. > > However, I dont think that this is a usefull example. One could use a > simple > obj.class.class_eval("..") to achieve the same. > > Dont you feel that allowing bind to attach methods only to objects that > already have this method (ie, obj.kind_of(class) == true) is strange? Probably. But you can have several versions of a method with this: class Foo def bar;"old" end end f = Foo.new puts f.bar -> "old" m = f.method(:bar).unbind puts m.bind(f).call -> "old" class Foo def bar;"new" end end puts f.bar -> "new" puts m.bind(f).call -> "old" Kind regards robert