(未定义的方法`+ @'表示[]:数组)

Pat*_*t R 3 arrays ruby-on-rails

当我尝试遍历一个对象数组时,我收到一条非常奇怪的错误消息.错误是

NoMethodError (undefined method `+@' for []:Array):
Run Code Online (Sandbox Code Playgroud)

这是该循环的代码.

#go through items and see if there are any corresponding offers 
    #All matches are stored in a hash
    items.each do |itemsi|
        bestoffer = -1
        matchescounter++ #matchescounter only get incredmented when all the offers have been taken care of
        offers.each do |offs|
        if itemsi.togive.to_str == offs.totake.to_str
            if offs.togive.to_int > bestoffer
                bestoffer = offs.togive.to_int
                matches[matchescounter].store(itemi, offer)         
            end#if
        end#if
        end#offers loop
    end#items loop
Run Code Online (Sandbox Code Playgroud)

我的代码中没有+ @.奇怪

JRL*_*JRL 11

Ruby中没有++运算符.

并且错误消息实际上非常清楚:它表示您的Array类型实例不存在名为"+ @"的方法.'+ @'是一元加实例方法的实际名称,它是为数字类型定义的,但不是为数组定义的.