Ruby | dig and fetch

dig and fetch are two powerful methods for manipulating a Hash object in Ruby.


Pass the comma separated keys in the order of the nesting to dig the hash and obtain the value.



This method fetches value for key from the hash provided.


fetch might raise KeyError if the key doesn't exist and you don't pass a default value.


Ahammed Nafih's photo

Learned something new! Keep up the good work :)

Sabarish Rajamohan's photo

Always had a confusion on which is better, now I have clarity, Thanks Vishnu!💎

Vishnuprasad K's photo

Happy Coding...