Why doesn’t this line of code work?
['fdfsd','gfdhgf'].inject(Hash.new){|sum,e| sum[e] = e}
Using ruby-1.9.2-p180, got IndexError: string not matched
Solved
['fdfsd','gfdhgf'].inject(Hash.new){|sum,e| sum[e] = e; sum}
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.
In 1.9 there’s also
each_with_object:Note that compared to
injectthe block arguments are reversed and that you don’t have to explicitly return the accumulator. In this specific case I’d go with J-_-L’s answer by the way.