我有两个数组
a = [:foo, :bar, :baz, :bof]
和
b = ["hello", "world", 1, 2]
我要
{:foo => "hello", :bar => "world", :baz => 1, :bof => 2}
有什么办法吗?
最佳答案
h = Hash[a.zip b] # => {:baz=>1, :bof=>2, :bar=>"world", :foo=>"hello"}
...该死,我喜欢 Ruby。
关于ruby - 如何从两个大小相等的数组构建 Ruby 哈希?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3359659/