title: Ruby arrays: right hand of statement changing through assignment even though I didn't tell it to
body: <p>I am doing some work with nested for loops. I want an array called holdRotated to be populated with certain elements in holdSmallerArea. However, during this assignment, for some reason, holdSmallerArea has changed, even though I didn't tell it to.</p>
  
  <pre><code>puts holdSmallerArea
  holdRotated[i][j] = holdSmallerArea[holdRotated.length - j - 1][i]
  puts holdSmallerArea
  
  Out:
  123
  456
  789
  
  723
  456
  789
  </code></pre>
  
  <p>As you can see in my code, I have not told holdSmallerArea to change, so why is it printing different things out?</p>
  
  <p>Full code:</p>
  
  <pre><code>$maze=
    ["123",
    "456",
    "789",]
  
  def plot x,y,distance
    holdSmallerArea = []
    holdRotated = []
    rows = []
    for i in 0..2 do
      for j in 0..2 do
        rows &lt;&lt; $maze[i][j]
      end
      rows = rows.join('')
      holdSmallerArea &lt;&lt; rows
      holdRotated &lt;&lt; rows
      rows = []
    end
  
    for i in (0..(holdRotated.length - 1)) do
        for j in (0..(holdRotated.length - 1)) do
          puts holdSmallerArea
          holdRotated[i][j] = holdSmallerArea[holdRotated.length - j - 1][i]
          puts holdSmallerArea
        end
    end
  end
  </code></pre>