Hi,

> The problem is that, unlike practically everything else in Ruby, each
> loops don't pass by reference, so my assignments get lost.
> 
> (...)
> 
> In PHP, I can add an ampersand (&) to the name (chunk, in this example)
> to pass by reference instead of by copy; is there something similar in
> Ruby, or should I be approaching this with a different method?

Ruby doesn't pass arguments by reference it passes them by value. What 
is passed to functions/blocks is the reference value. When you're 
assigning something to that variable, inside the block, you're getting a 
new object assigned to that variable and that's why it won't work. When 
you change an object that a variable holds reference to, you're changing 
that object, each time you assign you're placing a reference to a new 
object into that variable.

Creating an array let you pass the reference of that array, using that 
reference value you can change it's content. The method map! changes the 
object (! is a convention used in Ruby that indicates the method alters 
the receiver) so it will work also. The last option, suggested by 
Robert, assigns the result to the variable after method/block invocation 
so it'll work also.

If you still have doubts about pass-by-reference vs pass-by-value see 
how things work in C/C++ and in Java, the first is 
pass-by-reference/pass-by-copy and the other pass-by-value.

Pedro Silva.
-- 
Posted via http://www.ruby-forum.com/.