I’m confused as to this behavior. Do I really need to split my array to make this work?
pry(main)> ary = ["foo", "bar"]
=> ["foo", "bar"]
pry(main)> Hash[ary]
=> {"f"=>"o", "b"=>"a"}
pry(main)> Hash["foo", "bar"]
=> {"foo"=>"bar"}
pry(main)> Hash[["foo", "bar"]]
=> {"f"=>"o", "b"=>"a"}
pry(main)> Hash[ary.split(",")]
=> {"foo"=>"bar"}
Tries 1 and 3 above are equivalent, passing a single one dimensional array to the constructor, which is not correct.
For this to work as you expect, you’d need to pass the parameters as separate arguments, or as a 2 dimensional array of pairs>
The incorrect behavior you’re seeing is presumably because the constructor expects an array of length-2 arrays, while you’ve passed an array of strings. It interprets
arg[0]as the key for each pair, andarg[1]as the value, in this casefando,banda.