From: daz Date: 2005-04-20T11:12:55+09:00 Subject: Re: [PATCH] Trivial speedup in Array#zip From: Mauricio Fern�ndez > On Wed, Apr 20, 2005 at 07:02:24AM +0900, Nobu wrote: > > `tmp' can be modified or stored anywhere while yielding, [...] > > I see. What about this? > > [snip "this"] I guess Nobu's answer remains the same ? Here's a block that contains no assignments which is meant to capture [1, 4] in arr. Of course, it will be a reference to the object 'tmp' created in Array#zip. arr = [] [1,2,3].zip([4,5,6]){|x| arr.push(x) if x.include?(4)} p arr #-> [[1, 4]] With your change (reusing 'tmp'), the stored reference in arr would dynamically change throughout the zip loop and the final (very incorrect) value in arr would be [[3, 6]]. (Only one value was pushed by the code block, however, and it was the correct result at that time). Nobu's reply left me feeling acutely stupid for not considering the life of a yielded object. I admit; I'm not following the plot carefully enough. My excuse is that I was trying to draw a loaf of bread using an unfamiliar graphics package ;-)) daz