hash_var = array_var..inject({}) {|h, elem| h[elem[0]]=elem[1]; h}
Hash[ *{ :x => 1, :y => 2, :z => [3,4] }.to_a.flatten ] ArgumentError: odd number of arguments for Hash from (irb):1:in `[]' from (irb):1 { :x => 1, :y => 2, :z => [3,4] }.to_a.inject({}) { |m, e| m[e[0]] = e[1]; m } => {:y=>2, :x=>1, :z=>[3, 4]}
The discrepancy is because flatten recurses.
You need to create an account or log in to post comments to this site.