From: Robert Klemme Date: 2009-06-13T18:50:05+09:00 Subject: Re: Noob question, regarding array On 13.06.2009 11:36, Thiago wrote: > Im on chapter, Implementing a SongList Container, doing the code > samples, but i'm getting the following error when trying to run the > code: > 18:in `append': undefined method `push' for nil:NilClass > (NoMethodError) > from F:/InstantRails/rails_apps/test/test2.rb:80 > > I have a SongList class with the following method: > > def append(aSong) > @songs.push(aSong) > self > end > > and im trying to run the code sample as in the book: > > list = SongList.new > list. > append(Song.new('title1', 'artist1', 1)). > append(Song.new('title2', 'artist2', 2)). > append(Song.new('title3', 'artist3', 3)). > append(Song.new('title4', 'artist4', 4)) > > This doesnt make any sense. I can create the Song object just fine, > but if i try to add it to the array i get this erro. > Can anyone help me please? You did not show all the code but my guess would be that you did not initialize @songs properly in #initialize. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/