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.
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.