I have the following hash:
hash = {'name' => { 'Mike' => { 'age' => 10, 'gender' => 'm' } } }
I can access the age by:
hash['name']['Mike']['age']
What if I used Hash#fetch
method? How can I retrieve a key from a nested hash?
As Sergio mentioned, the way to do it (without creating something for myself) would be by a chain of fetch
methods:
hash.fetch('name').fetch('Mike').fetch('age')
fetch('name').fetch('Mike')
, no? – Sergio Tulentsev Oct 1 '13 at 12:14