From http://www.rubycentral.com/ref/ref_c_array.html#collect_oh:

"Invokes block once for each element of arr, replacing the element with 
the value returned by block."

Okay, so I attempt to execute the following code:


a=3
b=8
[a,b].collect! { |c| c = sprintf('%02d', c) }
puts a # prints out 3 and not 03


However, this code:


a=3
b=8
(a,b) = [a,b].collect! { |c| c = sprintf('%02d', c) }
puts a # prints out 03


Why is that?

If it's of any use, this is ruby 1.8.4 (2005-12-24) [i386-cygwin].

Thanks for demystification.

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