Hi everyone,
I’m feeling a bit surprised with the results that I’m getting from .do
while attempting to do something basic.
I have a multidimensional array, and when using the .do
method I expect to get each subarray. However, I’m getting quite different results. Can someone please explain why.
z = [[1, [100, 110]], [2, [200, 220]], [3, [300, 330]]];
z.do { |array, i| array[i].postln };
When I run the do
loop, I expect to get:
[ 1, [ 100, 110 ] ]
[ 2, [ 200, 220 ] ]
[ 3, [ 300, 330 ] ]
-> [ [ 1, [ 100, 110 ] ], [ 2, [ 200, 220 ] ], [ 3, [ 300, 330 ] ] ]
However what I actually see post is:
1
[ 200, 220 ]
nil
-> [ [ 1, [ 100, 110 ] ], [ 2, [ 200, 220 ] ], [ 3, [ 300, 330 ] ] ]
What gives?
Thanks!