From: dblack@... Date: 2006-03-17T05:28:41+09:00 Subject: Re: specify a mandatory block parameter Hi -- On Fri, 17 Mar 2006, Shea Martin wrote: > I think I know the answer to this already, but... > > Is there a what to make a block parameter mandatory? > > > def no_block( p_str ) > puts "#{p_str}" I believe that in every case, that's exactly equivalent to: puts p_str because #{...} interpolates the results of a to_s call, and puts also calls to_s. > end > > def block( &p_block ) > puts "#{p_block}" > end > > no_block #this will cause an exception > block #this doesn't, but is still missing parameter? > > > I know, I could just raise my own exception if p_block == nil, just wondering > why the difference? Or am I wrong? The block is really in its own category as a semantic (and syntactic) thing. You can hook into it in the arglist, but it's really a separate construct -- more on the logical level of the arglist itself, rather than a particular argument. You can test for the presence of a block with block_given? or its synonym, iterator? David -- David A. Black (dblack@wobblini.net) Ruby Power and Light, LLC (http://www.rubypowerandlight.com) "Ruby for Rails" chapters now available from Manning Early Access Program! http://www.manning.com/books/black