I am not sure in what situation I would want to use Hash#fetch over Hash#[]. Is there a common scenario in where it would be of good use?
I am not sure in what situation I would want to use Hash#fetch over
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Three main uses:
When the value is mandatory, i.e. there is no default:
You get a nice error message too:
When the value can be
nilorfalseand the default is something else:When you don’t want to use the
default/default_procof a hash: