From: Joel VanderWerf Date: 2006-02-05T06:51:25+09:00 Subject: optional yield -- was Re: Quiz #65, Principle of Great Surprise, and Array.delete sledgehammer Dave Howell wrote: > And it had an optional "yield." I'm mystified as to how to make THAT > part work, since neither ri nor the Pickaxe book gave me any hint at all > as to how to detect IF a block is present, and yield if it is. Just > using "yield" got me an error since I wasn't using a block in this case. Use Kernel.block_given?, like this: def one_two_three if block_given?; yield 1; yield 2; yield 3; else [1,2,3] end end See the PickAxe, in the chapter on blocks and iterators, page 51. -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407