array = [1,2,3,4]
data = [{number: 1, index: 0}, {number: 2, index: 1}, {number: 3, index: 2}, {number: 4, index: 3}]
我现在是这样做的
2.0.0-p481 :040 > data = {}
=> {}
2.0.0-p481 :041 > su = []
=> []
2.0.0-p481 :042 > array.each do |arr|
2.0.0-p481 :043 > data["number"] = arr
2.0.0-p481 :044?> data["index"] = arr + 1
2.0.0-p481 :045?> su << data
2.0.0-p481 :046?> end
=> [1, 2, 3, 4]
2.0.0-p481 :047 > su
=> [{"number"=>4, "index"=>5}, {"number"=>4, "index"=>5}, {"number"=>4, "index"=>5}, {"number"=>4, "index"=>5}]
2.0.0-p481 :048 >
出来的都是一样的