title: Chef Ruby hash.merge VS hash[new_key]
body: <p>I ran into an odd issue when trying to modify a chef recipe. I have an attribute that contains a large hash of hashes. For each of those sub-hashes, I wanted to add a new key/value to a 'tags' hash within. In my recipe, I create a 'tags' local variable for each of those large hashes and assign the tags hash to that local variable.</p>
  
  <p>I wanted to add a modification to the tags hash, but the modification had to be done at compile time since the value was dependent on a value stored in an input json. My first attempt was to do this:</p>
  
  <pre><code>tags = node['attribute']['tags']
  tags['new_key'] = json_value
  </code></pre>
  
  <p>However, this resulted in a spec error that indicated I should use node.default, or the equivalent attribute assignment function. So I tried that:</p>
  
  <pre><code>tags = node['attribute']['tags']
  node.normal['attribute']['tags']['new_key'] = json_value
  </code></pre>
  
  <p>While I did not have a spec error, the new key/value was not sticking.</p>
  
  <hr>
  
  <p>At this point I reached my "throw stuff at a wall" phase and used the hash.merge function, which I used to think was functionally identical to hash['new_key'] for a single key/value pair addition:</p>
  
  <pre><code>tags = node['attribute']['tags']
  tags.merge({ 'new_key' =&gt; 'json_value' })
  </code></pre>
  
  <p>This ultimately worked, but I do not understand why. What functional difference is there between the two methods that causes one to be seen as a modification of the original chef attribute, but not the other?</p>