如何將[5, 6, 7]
的每個元素賦值爲row
的值並使row
變爲{1=>5, 2=>6, 3=>7}
?向Hash.values賦值的數組的最佳方式是什麼
row = {1=>0, 2=>1, 3=>0}
#this following line doesn't work of course
row.values = [5, 6, 7]
#NoMethodError: undefined method `values=' for {1=>0, 2=>1, 3=>0}:Hash
row
#I want: {1=>5, 2=>6, 3=>7}
謝謝,我決定使用'Hash [row.keys.zip([5,6,7])]''。 – randomor 2013-04-08 15:16:28