From: Sean O'Halpin Date: 2011-03-14T01:18:16+09:00 Subject: Re: send() with a block? On Sun, Mar 13, 2011 at 2:54 PM, Peter Zotov wrote: > On Sun, 13 Mar 2011 23:26:01 +0900, Brian Candler wrote: >> >> Peter Zotov wrote in post #987115: >>> >>> On Sun, 13 Mar 2011 06:01:31 +0900, Sean O'Halpin wrote: >>>> >>>> define_method(). >>>> >>> >>>  But send() still bothers to pass the block around. Consider the >>>  following code: >>> >>>  ---8<---8<--- >>>  def my_method >>>   p block_given? >>>  end >>> >>>  def my_send # imitating send >>>   my_method >>>  end >>> >>>  my_send # => false >>>  ---8<---8<--- >> >> But compare with this: >> >> def my_method >>  p block_given? >> end >> >> def my_send(&blk) # imitating send >>  my_method(&blk) >> end >> >> my_send # => false >> my_send { :wibble } # => true > > That's the whole point of my demonstration. (Maybe I was too concise.) You were so concise you left out the thing you were trying to demonstrate: def my_send p block_given? end my_send { p 42 } #=> true > Any send-like method should to a trick like that to get the block-passing > behavior. It is not implicit. It /is/ implicit and is true for any method call. That's how you can do this: def my_yield yield end my_yield { p 42 } #=> 42 You specify the &block parameter when you want to do something with the block. Regards, Sean