I have an array. As example:
a = ["foo", "bar", "baz"]
I want to convert it to a hash:
h = { "foo" => randomvalue1, "bar" => randomvalue2, "baz" => randomvalue3 }
I come up with following way:
Hash[* a.map { |value| [value, randomvalue_generator] }.flatten]
My experience with Ruby quite limited, but have a feeling that there should be simler way of doing this. Mainly, I am interested in reducing code complexity.
Your way is fine except you do not need to
flattenorsplatThere many other ways to accomplish this but I like your original solution.