2013-04-21 84 views

回答

0

@npcRangedListnil。您可能要將其設置爲initialize

+0

這是涉及錯誤的所有代碼: – user2305561 2013-04-22 00:53:41

1

明顯@npcRangedListnil。沒有看到更多的代碼,沒有人能夠告訴你爲什麼。

0

也許下面的方式可以處理這種情況。我只是試圖創造和一個可能的方式來重新生成錯誤,你得到了相同的一個可能的分辨率:

class Foo 
def intialize 
end 
def showval 
    @arr[2] = 2 
    @arr 
end 
end 

p Foo.new.showval #=> `showval': undefined method `[]=' for nil:NilClass (NoMethodError) 

現在如果我我們寫的同一類下面,誤差不會泛起。

class Foo 
def initialize 
    @arr ||= [] 
    end 
def showval 
    @arr[2] = 2 
    @arr 
end 
end 

p Foo.new.showval #=> [nil, nil, 2] 
相關問題