DEV Community

Shilpi Agrawal
Shilpi Agrawal

Posted on • Updated on

One liner to fetch the value from hash in Ruby.

Struggling with fetching values from nested hash and looking for one liner, to get the work done.
Here, is something really fun I have found. Have a look at it.

Alt Text

Have fun using it. And don't forget to drop some love and comment.

Top comments (2)

Collapse
 
rahul_ramfort profile image
Rahul

Pro Tip:
Use safe navigation to handle nil case

cat&.dig(:breed, :persian_cat, :name)
Collapse
 
shilpi230 profile image
Shilpi Agrawal

Thanks! Rahul, thats helpful.