Daniel Schierbeck
4/12/2006 3:19:00 PM
OliverMarchand wrote:
> I am guessing your code does not what you want it to do:
>
> (a) In the inside version you are returning the first element, which
> you could do with [0], instead of each
>
> (b) in the second version you are rturning the last one, successively
> overwriting os. Use [-1] if that is waht you intend.
>
> Am I guessing right that this is not what you would like?
>
> Back to your original question: I am not an expert, but I would guess
> it is clearer to return from the outside, because the return inside a
> code block could be confused with the result passed back to the
> iterator. --- I am also awaiting other anwsers
I can't find the post you replied to, but I guess the author of it asked
how to manually stop a block from being executed, and return a value?
(1...5).each { |num| break num if num > 2 } => 3
Cheers,
Daniel