From: Robert Klemme Date: 2008-09-11T15:33:24+09:00 Subject: Re: pass by reference in each loop On 11.09.2008 03:24, Xiong Chiamiov wrote: > Anton Ivanov wrote: >> Xiong Chiamiov wrote: >> >>> The problem is that, unlike practically everything else in Ruby, each >>> loops don't pass by reference, so my assignments get lost. >>> >> You're confused. The variable chunk contains a reference to an object. >> You are assigning a different reference to that variable, that's all. > > Ah, that makes sense. I was a bit puzzled by that behavior, since it > seemed like everything in Ruby passed by reference, but your explanation > helped me get it straight in my mind. > > Tim Hunter wrote: >> Check out Array#map! > > That looks exactly right. Thanks! Note that you can do @question, @answer_explanation = [@question, @answer_explanation].map {|x| f(x)} Btw, if this happens often, you probably rather want your variables in an array anyway. Cheers robert