On Sun, 20 Feb 2011 19:51:22 +0900
Zengqh M. [email protected] wrote:
appreciate for your help.
You have only defined a “duration=” method on your class, and an
instance variable “@duration”. Calling “song.duration” means invoking a
method “duration” on object “song”, which is not defined in class Song.
You can define it this way:
Or, in more concise way, this way:
@duration = duration
Executing attr_accessor helper method in a class context is the same as
the definition of two functions, “duration” and “duration=”, as they’re
described above. You can also use attr_reader and attr_writer method; I
hope their function is obvious.