what do you know,
a,b,c = [a,b,c].map! { |x| x = do_something(x) }
actually works
I tried:
[a,b,c] = [a,b,c].map! { |x| x = do_something(x) }
but it returned error
There's so many little stuff you gotta know, I wasted whole 2 hours on
this "problem" 
I thought since I used explicit method map! that it will alter value of
each separate variable that's member of that array, but apparently it
doesn't
a = 5
[a].map! {|x| x*2 }
#=> [10]
puts a
#=> 5
There is a fundamental misunderstanding here of how Ruby variables work.
> a,b,c = [a,b,c].map! { |x| x = do_something(x) }
^- this is working because you are reassigning to a, b, and c. The "x = ..." does nothing, it's assigning to the local variable "x" inside the block. Coincidentally, the result of an assignment is the value assigned. This value happens to be returned by the block because it is the last expression in the block. After calling #map!, the array contains the results of calling do_something on each variable. As noted elsewhere, though, #map would work just as well in this case because the array is never explicitly stored anywhere.
The contents of the array are assigned back to a, b, and c in the assignment expression. Ruby matches the variables to values in the array by position. In other words, "c, b, a = [a,b,c].map! { ... }" would have a different result.
Each time the block is called, a new local variable "x" is created which refers to the value of an element from the array. It does _not_ refer to the variables "a, b, c". In fact, there is no way to get at those variables from the array, because the array just contains the values referred to by those variables. The values don't know what variables refer to them.
Consider this:
$ irb
2.0.0p247 :001 > a = 1
=> 1
2.0.0p247 :002 > b = a
=> 1
2.0.0p247 :003 > b
=> 1
2.0.0p247 :004 > a = 2
=> 2
2.0.0p247 :005 > b
=> 1
In Ruby assignments, the right-hand side is always a value. The left-hand side is a name/label/variable. Variables refer to values, not other variables. So you cannot hand a variable to a method or block and change the value it refers to. Occasionally you can _modify_ the value itself, but that is not the same as changing which value the variable is referring to.
Hope that clarifies a little bit.
-Justin
···
On 12/05/2013 07:11 AM, Stu P. D'naim wrote: