title: Specifying default value for Hash of hashes in Ruby
body: <p>Lets say I have a Hash called person whose key is name and value is a hash having keys 'age' and 'hobby'. An entry in the hash person would look like</p>
  
  <pre><code>=&gt; person["some_guy"] = {:hobby =&gt; "biking", :age =&gt; 30}
  </code></pre>
  
  <p>How would I go about specifying the default for the hash 'person'? I tried the following</p>
  
  <pre><code>=&gt; person.default = {:hobby =&gt; "none", :age =&gt; 20}
  </code></pre>
  
  <p>but it doesn't work.</p>
  
  <p>EDIT:</p>
  
  <p>I was setting one attribute and expecting others to be auto-populated. For eg.</p>
  
  <pre><code>=&gt; person["dude"][:age] += 5
  </code></pre>
  
  <p>and this is what I was seeing</p>
  
  <pre><code>=&gt; person["dude"]
  =&gt; {:hobby =&gt; "none", :age =&gt; 25}
  </code></pre>
  
  <p>which is fine. However, typing <code>person</code> at the prompt, I get an empty hash.</p>
  
  <pre><code>=&gt; person
  =&gt; {}
  </code></pre>
  
  <p>However, what I was expecting was</p>
  
  <pre><code>=&gt; person
  =&gt; {"dude" =&gt; {:hobby =&gt; "none", :age =&gt; 25}}
  </code></pre>