From: James Edward Gray II Date: 2007-08-07T00:45:04+09:00 Subject: Re: yield or call? On Aug 6, 2007, at 10:39 AM, Phlip wrote: > Pit Capitain wrote: > >>> When writing API-style code, I always start with &block because >>> it's only a >>> matter of time before I refactor the code and start passing that >>> &block into >>> a helper method. >> >> Phlip, you can do the equivalent with yield: >> >> def x(&b); xx(&b); end >> def xx(&b); b.call; end >> >> vs. >> >> def y; yy { yield }; end >> def yy; yield; end >> >> Also in this case the yield version is much faster. > > What if the block were optional? You can use block_given? to find out if a block was provided. James Edward Gray II