On 7/14/06, Sean O'Halpin <sean.ohalpin / gmail.com> wrote:
> The problem is - as I'm sure you know - that define_method doesn't
> honour the block argument of the method reference. I'd be very
> interested to see if you can do it cleanly in ruby 1.8.
>
> Regards,
> Sean
>
Replying to myself to correct an error - it's the implicit to_proc (&)
that strips the block argument, not define_method itself.

This illustrates the (perhaps surprising) behaviour:

def m1(*args, &block)
  p args
  block.call if block_given?
end

m1(1) do
  puts "m1"
end

meth = method(:m1)

Object.instance_eval { define_method :m2, meth }

m2(2) do
  puts "m2"
end

Object.instance_eval { define_method :m3, &meth }

m3(3) do                        # this block is not called
  puts "m3"
end
__END__
[1]
m1
[2]
m2
[3]


Regards,
Sean