Undefined method `+'

hey guys the following line of code is producing a "undefined method
`+’:

@plays += 1

cheers,

Danny

What is the content of @plays?

Sam

Is it an “undefined method ‘+’ on NilClass”? If so, you forgot to
assign a value to @plays before incrementing it. You might try
something like this instead:

def plays
@plays ||= 0
end

def plays=(v)
@plays = self.plays + 1
end

~ jf

John F.
Principal Consultant, BitsBuilder
LI: http://www.linkedin.com/in/johnxf
SO: User John Feminella - Stack Overflow

Whoops, that’s what I get for copy-pasting into the wrong segment. You
are correct, Rob.

~ jf

John F.
Principal Consultant, BitsBuilder
LI: http://www.linkedin.com/in/johnxf
SO: User John Feminella - Stack Overflow

On Fri, Feb 18, 2011 at 10:29, Rob B.

On Feb 18, 2011, at 7:57 AM, John F. wrote:

end

~ jf

John F.
Principal Consultant, BitsBuilder
LI: http://www.linkedin.com/in/johnxf
SO: User John Feminella - Stack Overflow

I think you’d want:

def plays=(v)
@plays = v
end

In your original:

plays = 5
puts plays
1 # <== ???

I can’t imagine that’s what the OP wants to see.

On 18/02/11 17:01, Danny L. wrote:

Rob B.
[email protected] http://AgileConsultingLLC.com/
[email protected] http://GaslightSoftware.com/