From: "Ralf Müller" Date: 2005-04-21T14:57:37+09:00 Subject: Re: [NEWBIE]: Example from Pickaxe2 gives errors... (p. 31) On Thu, 21 Apr 2005 00:13:34 +0900 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.... > > song = Song.new() > => # > > song.name = "Blueberry Hill" > => "Blueberry Hill" > > song.name > => "Blueberry Hill" > > Have I misread / misunderstood the text? Why the errors? > > SM > > (Only 770 pages to go... Woohoo!) I think, you should add the 'initialzie' function from page 25. Otherwise, the Class Song inherits its Constructor from 'Object'. attr_writer :name, :artist, :duration only gives you direct write access on the 3 attributes trough Song.attribute, but it does not keep you from writing 'initialze'. All the Code examples of (at least) one chapter should be considered as ONE piece of code, if you try to get them run. Otherwise the authors would have to copy all the basic stuff into the examples for a special functionality, which would be pretty unreadyble. regards ralf