On 4/20/05, Simon.Mullis / equinoxsolutions.com <Simon.Mullis / equinoxsolutions.com> wrote: > Greeting all, > > How about a refreshingly easy question for a change.... > > Really, really basic question I know, but: > > class Song > attr_writer :name, :artist, :duration > end > => nil > > song = Song.new("Blueberry Hill", "Fats Waller", 320) > => ArgumentError: wrong number of arguments (3 for 0) > from (irb):24:in `initialize' > from (irb):24:in `new' > from (irb):24 > > However.... > Okay what it's telling you is that your initialize method (that you haven't defined) does not take any arguments, and you're passing it three. Try this. > class Song > attr_writer :name, :artist, :duration def initialize(name,artist,duration) @name=name @artist =artist @duration = duration end > end > song = Song.new() > => #<Song:0x2aab648> > > song.name = "Blueberry Hill" > => "Blueberry Hill" > > song.name > => "Blueberry Hill" > > Have I misread / misunderstood the text? Why the errors? > This section of code is indeed correct, as the attribute writers are allowing you to put data into the "name" attribute. If you add the constructor as listed above, it should work just fine. > SM >