I have a hash as follows:
drinks = {"soda" => 3, "water" => 2, "beer" => 6}
I would like to show the value of each pair tripled by using each.
In other words, I’d like “soda” to have a value of 9, “water” to have a value of 6, etc.
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.
There are a number of ways to do this, depending on the semantics you want. One way is to operate on each key/value pair with Hash#each. For example: