Undefined method `+'

D

Danny L.

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

@plays += 1


cheers,

Danny
 
R

Rob Biedenharn

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 Feminella
Principal Consultant, BitsBuilder
LI: http://www.linkedin.com/in/johnxf
SO: http://stackoverflow.com/users/75170/

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.



Rob Biedenharn
(e-mail address removed) http://AgileConsultingLLC.com/
(e-mail address removed) http://GaslightSoftware.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top