A
Alexey Verkhovsky
One example in The Ruby Way claims that in the following snippet second
line shuffles the a (i.e., makes an array consisting of the same
elements as a, but in a different order).
a = [1, 2, 3, 4, 5]
puts a.collect { a.slice!(rand(a.length)) }.inspect
The claim sounds reasonable, but in reality Ruby 1.9 (CVS HEAD) always
returns an array of three random elements, not of five as expected.
Why is that so?
Best regards,
Alexey Verkhovsky
line shuffles the a (i.e., makes an array consisting of the same
elements as a, but in a different order).
a = [1, 2, 3, 4, 5]
puts a.collect { a.slice!(rand(a.length)) }.inspect
The claim sounds reasonable, but in reality Ruby 1.9 (CVS HEAD) always
returns an array of three random elements, not of five as expected.
Why is that so?
Best regards,
Alexey Verkhovsky