title: ruby add new key-value pair to nested hash
body: <p>Suppose we have a nested hash here.</p>
  
  <pre><code>a = {:"0" =&gt; {:CA =&gt; {:count =&gt; 10}}}
  </code></pre>
  
  <p>if we want to add a new hash pair to that hash, say</p>
  
  <pre><code>a = {:"0" =&gt; {:NY =&gt; {:count =&gt; 11}}} 
  </code></pre>
  
  <p>and let it become</p>
  
  <pre><code>a = {:"0" =&gt; {:CA =&gt; {:count =&gt;10}, :NY =&gt; {:count =&gt; 11}}}
  </code></pre>
  
  <p>what should I do?</p>
  
  <p>I've tried</p>
  
  <pre><code>a[:0][:NY][:count] = 11
  </code></pre>
  
  <p>but get the error "undefined method `[]=' for nil:NilClass (NoMethodError)"</p>