我不得不重新安排我的目的地的哈希值,所以我想打一個數組中像這樣的數組紅寶石:Mutidimensional陣列上軌
@orderedDestinations = Array.new
@destinations.each do |destination|
if (destination.position != nil)
@orderedDestinations[destination.position][destination.id] = destination
end
end
我得到這個錯誤:
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.[]=
我做錯了什麼?
偏題,但你應該真的使用'#nil?'謂詞,而不是將對象與'nil'進行比較;) – d11wtq
或者甚至不打擾任何零比較 - 'if destination.position' –