title: How to deal with potential errors while accessing a hash inside a hash?
body: <p>Sometimes while dealing with API responses, I'll end up writing something like:</p>
  
  <pre><code>what_i_need = response["key"]["another key"]["another key 2"]
  </code></pre>
  
  <p>The problem with that is, it'll throw an error if, say, <code>"another key"</code> is missing. I don't like that. I'd be a lot happier if <code>what_i_need</code> turned up a <code>nil</code> if something along the process broke.</p>
  
  <p>Is there a more elegant solution than:</p>
  
  <pre><code>what_i_need = nil
  begin
    what_i_need = response["key"]["another key"]["another key 2"]
  rescue Exception =&gt; e
  end
  </code></pre>
  
  <p>I also thought about monkey patching NilClass you try to access <code>nil["something"]</code> it would return <code>nil</code>, but I'm not sure if that's the best way to go about it either of if it's possible even.</p>