title: Ruby: How to get a list of keys to reach a leaf key in nested hash
body: <pre><code>h = {:c=&gt;{:b=&gt;"ss"}, :a=&gt;{:e=&gt;{:b=&gt;"foo"}}, :x=&gt;{:y=&gt;{:z=&gt;{:b=&gt;"hai"}}}}
  </code></pre>
  
  <p>I need a method which will return all nested keys to reach a given leaf level key</p>
  
  <p>for example, </p>
  
  <pre><code>h.paths_to(:b) =&gt; [[:c],[:a,:e],[:x,:y,:z]]
  </code></pre>
  
  <p>I know only the key name what I am looking for, which is ':b'. It may exist at any level in depth of this hash and at multiple places. The method should return all the paths (keys) to reach the given key in this nested hashes.</p>
  
  <p>Note: the key will not be having another hash as value.</p>
  
  <p>I tried several ways, could not identify a solution. Please help.</p>