Problem with irb and ruby programming

I’reading “pragmatic programmers guide” on ruby-doc site.
this simple example, written on irb shell,

class Song
@@plays = 0
def initialize(name, artist, duration)
@name = name
@artist = artist
@duration = duration
@plays = 0
def play
@plays += 1
@@plays += 1
“This song: #@plays plays. Total #@@plays plays.”

after to have insert some simple data,
when executed method “play”,
return me that error :
undefined method `+’ for nil:NilClass

why ?
is not possible use operator “+=” ?
I don’t believe that !!
any suggestions ?
thank’s in advance

bye by fellons

so, when I write:

song =“She loves you”, “Beatles”, 120)
song2 =“Eleanor Rigby”, “Beatles”, 90)

I get :

This song: 1 plays. Total 1 plays.
This song: 1 plays. Total 2 plays.

which is right, surely?


sorry, I have make a stupid mistake.
please, excuse me :frowning:

bye by fellons