Hash.each returns an array [key, value],
but if I want a hash?
Example: {:key => value }
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.
I’m assuming you meant “yields” where you said “return” because
Hash#eachalready returns a hash (the receiver).To answer your question: If you need a hash with the key and the value you can just create one. Like this:
There is no alternative
eachmethod that yields hashs, so the above is the best you can do.