From: Steve Callaway Date: 2005-02-12T05:15:53+09:00 Subject: Re: a problem outputting text Try this: class Song attr_reader :name, :duration attr_writer :name, :duration def initialize ( name, duration) @name = name @duration = duration end def print puts "The song title is #{@name} and the track length is #{@duration} " end def set_duration( newduration) @duration = newduration end end asong = Song.new( "Good Golly Miss Molly", 240) asong.print puts asong.name puts asong.duration The problem is the embracement in print: below > puts {"The song title is #{@name} and the > track length is > #{@duration} /n" } <- and here Also be wary of using variables with the same name as methods as in e.g. duration since Ruby will try and evaluate the variable as a method or vice versa dependant on where you are in the code. --- "Ghelani, Vidhi" wrote: > Hey, > > > > I am trying to test some of my code. Here it is : > > ************************************************************************ > ************************* > > class Song > > > > def duration= (newDuration) > > @duration = newDuration > > end > > > > def initialize(name, duration) > > @name = name > > @duration = duration > > end > > > > attr_reader :name, :duration > > attr_writer :name, :duration > > > > def print > > puts {"The song title is #{@name} and the > track length is > #{@duration} /n" } > > end > > > > > > end > > > > > > asong = Song.new("Mahi Ve", 2443) > > asong.print > > asong.name > > asong.duration > > > > ************************************************************************ > *********************** > > However, this does not print anything. There are no > errors showing up > either. All that happens is that it prints blank > lines. > > > > Does anyone know where I am going wrong ? > > > > Any help would be appreciated. > > > > Thanks, > > Vidhi > > > >