From: Florian Gross Date: 2005-01-29T09:10:51+09:00 Subject: Re: Proc rebinding Csaba Henk wrote: > A Proc obejct carries its binding with itself (ie. is a closure), as it > is well known. When @@hello was created, it did not know any @name. But > then it was passed to define_method, and the resulting method "hello" > can find @name in the instances. That is, ruby altered the bindings of > (some kind of copy of) @@hello, and only after that has it been attached > as a method. (Or rather, the binding is altered upon instantiation?) > > [...] > * Is it possible with EvilRuby? Yes, EvilRuby has Proc#self= which will change the self-context of a block. Which might be a bad idea because Ruby might expect Procs to be immutable, but I've not experienced any oddities yet. If I'm not completely wrong this will however not change the scope of a proc meaning it will still refer to the surrounding variables. (So the result is a bit similar to using .instance_eval().) Regarding methods: You can cheat there by using obj.method(:x).unbind.force_bind(other_obj) which is also available in a limited version in EvilRuby.