From: dblack@... Date: 2006-01-05T11:13:11+09:00 Subject: Re: Default block parameter? Hi -- On Thu, 5 Jan 2006, Mark J.Reed wrote: > Okay, this is probably a dumb question, but how do I declare an > optional block parameter with a default value? > > I tried several variations on this basic theme: > > def meth(&block = lambda { |i| ... }) > ... > end > > But I keep getting syntax errors. Help? The &block thing is a special dispensation from Ruby, letting you grab the block but not serving as a normal argument. The way I've always seen this done is: def meth(&block) block ||= lambda { ... } ... end I don't think there's a way to do it inside the arglist. David -- David A. Black dblack@wobblini.net "Ruby for Rails", from Manning Publications, coming April 2006! http://www.manning.com/books/black