On Apr 22, 2007, at 9:35 PM, Ball, Donald A Jr (Library) wrote:

>> That's pretty much what I did (as well as some others) but yours is
>> much more elegant. I didn't really think about using a block with the
>> recursion. Cool.
>
> Thanks. That's actually the first time I've written code that  
> yields. It's actually bit unclear to me as to when it's better to  
> return results and when it's better to yield them. I guess the best  
> thing to do would be to check, what is it, block_given? and either  
> yield or collect the results as appropriate. Do more advanced  
> rubyists have any guidance to offer in this regard?

I prefer to yield whenever you don't need a full set of results to do  
something useful.  This means I don't have to aggregate results,  
which saves memory.  It also means the calling code gets answers as  
soon as they are available.  Plus, if that calling code really wanted  
to fill an Array with the results they can certainly do that.   
Basically, it gives the caller more choices.

James Edward Gray II