"Robert Klemme" <bob.news / gmx.net> wrote

> From all that I know you can't because you cannot do any of these:
>
>  - bind an instance method of A to B (unless B is a superclass of A)
>
>  - convert a method to a proc that is usable with instance_eval.
>
> The question is: does it make sense to do that?

How do you mean "make sense"? Does my desired behavior make sense (it does
to me)? Or does it make sense for Ruby to permit one of the 2 approaches you
suggest (#2 does, not sure I understood #1)?

Thanks.

btw, my guess at what the instance_eval version might look like:

class B
 def initialize delegatee
   @a = delegatee
 end
 def method_missing sym, *args, &block
  m = @a.method sym
  self.instance_eval m, *args, &block
 end
end