Here is my code:
but = Array.new(2, []) # => [[], []]
but[1] << 1
but # => [[1], [1]]
If I create an array using this:
but = [[], []]
then the problem does not occur. However, the quantity of subarrays I need to include into but
is not a stable variable, and alternatives I know to Array.new
, loops etc., are cumbersome.
Why does this happen? Doesn't but[1] << 1
affect only one specific sub-element?