我似乎無法重寫我的紅寶石代碼中的變量。2d數組變量覆蓋在ruby中不起作用?
我有兩個二維數組稱爲table
和updated_table
,updated_table
繼承的table
的價值觀和工作,但隨後在後面的代碼,更改了updated_table
的值進行,當我嘗試設置updated_table
回相同的值(州)table
這不起作用。
這是爲什麼? 我試圖做的很簡單的例子。
class SomeClass
table = [[0,20,5,1000,1000], [20,0,10,8,20], [5,10,0,1000,40], [1000,8,1000,0,6], [1000,20,40,6,0]]
updated_table = table
##
then here i have some code that makes changes to the values in the updated_table
##
2.times do
updated_table = table # this dosent work??
## do some more calculations and so on ##
end
end
你爲什麼要這樣做兩次? (你也可以做'2times') – 2011-03-05 03:05:07
這只是一個例子,實際代碼中有邏輯確定每次循環和計算這個表的次數。 – 2011-03-05 03:07:13