Robert Klemme
9/11/2008 6:37:00 AM
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