I created an array by doing the following:
@gameboard = Array.new(3, Array.new(3, " "))
I tried to assign a value like so, and I got this:
@gameboard[0][2] = "X"
@gameboard #=> [[" ", " ", "X"], [" ", " ", "X"], [" ", " ", "X"]]
When I declare the array differently,
@gameboard = [[" ", " ", " "], [" ", " ", " "], [" ", " ", " "]]
I get this result:
@gameboard[0][2] = "X"
@gameboard # => [[" ", " ", "X"], [" ", " ", " "], [" ", " ", " "]]
Why does using the Array.new
method illicit different behavior when assigning values to the array?