Can any one tell me why the following:
[\'a\', \'b\'].inject({}) {|m,e| m[e] = e }
throws the error:
IndexError: string no
Your block needs to return the accumulating hash:
['a', 'b'].inject({}) {|m,e| m[e] = e; m }
Instead, it's returning the string 'a' after the first pass, which becomes m in the next pass and you end up calling the string's []= method.
m
[]=