title: how to create hash of hashes in ruby
body: <p>UPDATE: the answer is below by me a simple .merge is what was needed.</p>
  
  <p>I need to get a hash of hashes as output from my build_virtual_boards_hash method
  I can not figure out how to add the hash to a stack of hashes. Or even how to create such a thing...first I'll list the methods out and then show you the output I am getting.</p>
  
  <p>Here are the two methods that are used...the problem is located inside 'build_virtual_boards_hash'...</p>
  
  <pre><code>def build_virtual_boards_hash(board, player)
    virtual_board = board.dup
  
    virtual_board_hash = {}
    new_board_hash = {}
  
    empty_spaces_on_board = virtual_board.grid.select{ |k, v| v == " " }.keys
    index_mark = 'VB'+empty_spaces_on_board.length.to_s
  
    #THIS IS WHERE I THINK THE PROBLEM IS
    #HOW DO I ADD EACH LOOP RESULT TO -SOMETHING- 
    #THAT CAN BE CALLED ON LATER AFTER THE LOOP ENDS
    #SO I GET THE DESIRED RESULTING OUTPUT?
    # 
    empty_spaces_on_board.each do |empty_space_symbol|
      # create a hash
      new_board_hash = {index_mark =&gt; move_as_somebody(board, player, empty_space_symbol).grid} #value
      p new_board_hash  
    end
  
  end
  
  
  #takes board....returns new board
  def move_as_somebody(board, player, empty_space)
    new_board = board
    if player == 'X'
      new_board.grid[empty_space] = player
    else
      player == 'O'
      new_board.grid[empty_space] = player
    end
    return new_board
  end
  </code></pre>
  
  <p>I currently get this output from these two methods...</p>
  
  <pre><code>{"VB7"=&gt;{:a1=&gt;"X", :a2=&gt;"X", :a3=&gt;" ", :b1=&gt;" ", :b2=&gt;"O", :b3=&gt;" ", :c1=&gt;" ", :c2=&gt;" ", :c3=&gt;" "}}
  {"VB7"=&gt;{:a1=&gt;"X", :a2=&gt;"X", :a3=&gt;"X", :b1=&gt;" ", :b2=&gt;"O", :b3=&gt;" ", :c1=&gt;" ", :c2=&gt;" ", :c3=&gt;" "}}
  {"VB7"=&gt;{:a1=&gt;"X", :a2=&gt;"X", :a3=&gt;"X", :b1=&gt;"X", :b2=&gt;"O", :b3=&gt;" ", :c1=&gt;" ", :c2=&gt;" ", :c3=&gt;" "}}
  {"VB7"=&gt;{:a1=&gt;"X", :a2=&gt;"X", :a3=&gt;"X", :b1=&gt;"X", :b2=&gt;"O", :b3=&gt;"X", :c1=&gt;" ", :c2=&gt;" ", :c3=&gt;" "}}
  {"VB7"=&gt;{:a1=&gt;"X", :a2=&gt;"X", :a3=&gt;"X", :b1=&gt;"X", :b2=&gt;"O", :b3=&gt;"X", :c1=&gt;"X", :c2=&gt;" ", :c3=&gt;" "}}
  {"VB7"=&gt;{:a1=&gt;"X", :a2=&gt;"X", :a3=&gt;"X", :b1=&gt;"X", :b2=&gt;"O", :b3=&gt;"X", :c1=&gt;"X", :c2=&gt;"X", :c3=&gt;" "}}
  {"VB7"=&gt;{:a1=&gt;"X", :a2=&gt;"X", :a3=&gt;"X", :b1=&gt;"X", :b2=&gt;"O", :b3=&gt;"X", :c1=&gt;"X", :c2=&gt;"X", :c3=&gt;"X"}}
  </code></pre>
  
  <p>What I need is this...</p>
  
  <pre><code>virtual_boards = {
      {"VB7"=&gt;{:a1=&gt;"X", :a2=&gt;"X", :a3=&gt;" ", :b1=&gt;" ", :b2=&gt;"O", :b3=&gt;" ", :c1=&gt;" ", :c2=&gt;" ", :c3=&gt;" "}},
      {"VB6"=&gt;{:a1=&gt;"X", :a2=&gt;"X", :a3=&gt;"X", :b1=&gt;" ", :b2=&gt;"O", :b3=&gt;" ", :c1=&gt;" ", :c2=&gt;" ", :c3=&gt;" "}},
      {"VB5"=&gt;{:a1=&gt;"X", :a2=&gt;"X", :a3=&gt;"X", :b1=&gt;"X", :b2=&gt;"O", :b3=&gt;" ", :c1=&gt;" ", :c2=&gt;" ", :c3=&gt;" "}},
      {"VB4"=&gt;{:a1=&gt;"X", :a2=&gt;"X", :a3=&gt;"X", :b1=&gt;"X", :b2=&gt;"O", :b3=&gt;"X", :c1=&gt;" ", :c2=&gt;" ", :c3=&gt;" "}},
      {"VB3"=&gt;{:a1=&gt;"X", :a2=&gt;"X", :a3=&gt;"X", :b1=&gt;"X", :b2=&gt;"O", :b3=&gt;"X", :c1=&gt;"X", :c2=&gt;" ", :c3=&gt;" "}},
      {"VB2"=&gt;{:a1=&gt;"X", :a2=&gt;"X", :a3=&gt;"X", :b1=&gt;"X", :b2=&gt;"O", :b3=&gt;"X", :c1=&gt;"X", :c2=&gt;"X", :c3=&gt;" "}},
      {"VB1"=&gt;{:a1=&gt;"X", :a2=&gt;"X", :a3=&gt;"X", :b1=&gt;"X", :b2=&gt;"O", :b3=&gt;"X", :c1=&gt;"X", :c2=&gt;"X", :c3=&gt;"X"}}
  }
  </code></pre>
  
  <p>How do I accomplish this?</p>