Selective mixins; who can improve on this?

Here's my solution:

require 'nodewrap'

class Module
  def use(mod, *methods)
    methods.each do |method|
      sym = method.to_sym
      body = mod.instance_method(sym).body
      add_method(sym, body, 0)
    end
  end
end

Be careful,

Paul

Paul Brannan wrote:

Here's my solution:

require 'nodewrap'

class Module
  def use(mod, *methods)
    methods.each do |method|
      sym = method.to_sym
      body = mod.instance_method(sym).body
      add_method(sym, body, 0)
    end
  end
end

This doesn't work for me. There appears to be no UnboundMethod#body method, even after requiring nodewrap.

What's missing?

Regards,

Dan

The latest version of nodewrap is missing. :slight_smile:

I fixed this a year ago but haven't done a release yet. Get nodewrap
from cvs and you'll get UnboundMethod#body (along with lots of other
cool prizes).

Paul

···

On Thu, Sep 08, 2005 at 02:52:41AM +0900, Daniel Berger wrote:

This doesn't work for me. There appears to be no UnboundMethod#body
method, even after requiring nodewrap.

What's missing?