title: Accessing elements of nested hashes in ruby
body: <p>I'm working a little utility written in ruby that makes extensive use of nested hashes.  Currently, I'm checking access to nested hash elements as follows:</p>
  
  <pre><code>structure = { :a =&gt; { :b =&gt; 'foo' }}
  
  # I want structure[:a][:b]
  
  value = nil
  
  if structure.has_key?(:a) &amp;&amp; structure[:a].has_key?(:b) then
    value = structure[:a][:b]
  end
  </code></pre>
  
  <p>Is there a better way to do this?  I'd like to be able to say:</p>
  
  <pre><code>value = structure[:a][:b]
  </code></pre>
  
  <p>And get <code>nil</code> if :a is not a key in <code>structure</code>, etc.</p>