R
RichardOnRails
Hi,
I wrote the following intending to create an array of 3 element, each
being itself an array of two elements initialized to zero; Judging by
"inspect", I seem to have that:
a = Array.new(3, [0,0]) => [[0, 0], [0, 0], [0, 0]]
I tried the following, which confirms that a[0] is indeed a sub-
array.
a[0].inspect + "; " + a[0].class.to_s => [0, 0]; Array
Then I tried to assign a number (5) to the first element of the first
sub-array. What I got was more 5's than I bargained for:
a[0][0]=5 => [[5, 0], [5, 0], [5, 0]]
What am I missing here?
Thanks in Advance,
Richard
I wrote the following intending to create an array of 3 element, each
being itself an array of two elements initialized to zero; Judging by
"inspect", I seem to have that:
a = Array.new(3, [0,0]) => [[0, 0], [0, 0], [0, 0]]
I tried the following, which confirms that a[0] is indeed a sub-
array.
a[0].inspect + "; " + a[0].class.to_s => [0, 0]; Array
Then I tried to assign a number (5) to the first element of the first
sub-array. What I got was more 5's than I bargained for:
a[0][0]=5 => [[5, 0], [5, 0], [5, 0]]
What am I missing here?
Thanks in Advance,
Richard