-1

我懂了:

first = [['lorem1','lorem1','lorem1',...],['lorem2','lorem2','lorem2',...],...]
second = [value1,value2,value3, ...]

我想做这样的事情:

my_array_of_hash = [{value 1 =>lorem1, value2 => lorem1}, {value1 =>lorem2, value2 => lorem2}, .... ]

你能帮我吗?

4

1 回答 1

3
hashes_array = []
first.each do |array|
  hashes_array << Hash[second.zip array]
end

或者:

hashes_array = first.map do |array|
  Hash[second.zip array]
end
于 2013-06-07T09:00:42.723 回答