title: Is there a solution to bypass 'can't add a new key into hash during iteration (RuntimeError)'?
body: <p>I have a big problem with the expected RuntimeError: "can't add a new key into hash during iteration"</p>
  
  <p>In my case a I have a YAML file: test.yaml - in which I have some keys already added.</p>
  
  <pre><code>test.yaml
  key1:
  key2:
  key3:
  </code></pre>
  
  <p>I am getting the contents of the file in a variable:</p>
  
  <pre><code>file_hash = YAML.load_file("testm.yaml")
  </code></pre>
  
  <p>Then I need to loop through this hash and add other keys to them:</p>
  
  <pre><code>file_hash.each do |key|
     file_hash[key] = 'key_1'
     file_hash[key] = 'key_2'
  end
  File.open('test.yaml', 'w') { |f| YAML.dump(file_hash, f) }
  </code></pre>
  
  <p>The main issue is that I am unable to write into a hash while in a loop. I don't understand why this is expected, when you have the power to control the loop block.
  Is there another way in which I can accomplish what I showed above?</p>
  
  <p>Note: I am using RUBY 1.9.3 p547</p>