DEV Community 👩‍💻👨‍💻

Shilpi Agrawal for Main Street

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 Author

Thanks! Rahul, thats helpful.

🌚 Browsing with dark mode makes you a better developer.

It's a scientific fact.