3

I'm getting a very strange error message when I try to iterate through an array of objects. The error is

NoMethodError (undefined method `+@' for []:Array):

Here is the code of that loop.

#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

I don't have +@ anywhere in my code. Strange

3 Answers 3

11

There is no ++ operator in Ruby.

And the error message is actually quite clear: it says that the method named '+@' does not exist for your instance of the Array type. '+@' is the actual name of the unary plus instance method, which is defined for the Numeric type, but not for Array.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, that was my java getting back into my head.
0

I came across a similar error today.

NoMethodError (undefinded method `-@' for []:Array)

I had copy-pasted a %w array declaration from my HAML document into a ruby console to verify its formatting, and failed to notice that I included the - at the beginning.

Comments

0

I got this error when I put a =+ instead of a += while adding 2 arrays

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.