On Sat, Mar 12, 2011 at 9:11 PM, Peter Zotov <whitequark / whitequark.org> wr=
ote:
> On Sun, 13 Mar 2011 06:01:31 +0900, Sean O'Halpin wrote:
>>
>> On Sat, Mar 12, 2011 at 8:45 PM, 7stud -- <bbxx789_05ss / yahoo.com> wrote=
:
>>>
>>> Why don't the ruby docs say that send() can take a block?
>>>
>>> Kernel.send(:define_method, :my_meth) do |x|
>>> =A0puts x
>>> end
>>>
>>
>> It's not the send() that's consuming the block - it's the define_method(=
).
>>
>
> But send() still bothers to pass the block around. Consider the following
> code:
>
> ---8<---8<---
> def my_method
> =A0p block_given?
> end
>
> def my_send # imitating send
> =A0my_method
> end
>
> my_send # =3D> false
> ---8<---8<---
>
> --
> =A0WBR, Peter Zotov.
>
>

I'm not sure what you're showing me here. But consider this:

class Foo
  def self.send(*a, &block)
    p block_given?
    super(*a)
  end
end

class Bar
  def self.send(*a)
    p block_given?
    super(*a)
  end
end

Foo.send(:define_method, :my_method) do |x|
  p x
end

block =3D proc{ |x| p x }
Bar.send(:define_method, :my_method2, &block)

foo =3D Foo.new
foo.my_method(1)
bar =3D Bar.new
bar.my_method2(2)

def my_method(x)
  p x
end

my_method(10, &block)

__END__
true
true
1
2
10

Even when you explicitly do /not/ pass on the block (as in the
super(*a) call above), send() does not consume it.
Passing a block using the &block syntax is simply part of ruby's
method calling syntax.
A method does not have to specify that it takes a block for you to
call it with one.

Regards,
Sean