I am getting an error with this code below.. basically its meant to read
/jazz/j00132.mp3 3:45 Fats Waller Ain''t Misbehavin''
/jazz/j00319.mp3 2:58 Louis Armstrong Wonderful World
/bgrass/bg0732.mp3 4:09 Strength in Numbers Texas Red
from a text file, put it in an array and then display it but I am
getting error message.
C:/Rails/WeightConversion/lib/main.rb:36: undefined method `squeeze!''
for nil:NilClass (NoMethodError)
from C:/Rails/WeightConversion/lib/main.rb:34:in `each''
from C:/Rails/WeightConversion/lib/main.rb:34
Only started using ruby and rails this monday so I am still trying to
get the hang of how everything works. Any insights would be massively
appreciated.
class Song
def initialize (name, artist, duration)
@name = name
@artist = artist
@duration = duration
@plays = 0
end
end
class SongList
def initialize
@songs = Array.new
end
def append (aSong)
@songs.push(aSong)
end
def deleteFirst
@songs.shift
end
def deleteLast
@songs.pop
end
def [](key)
return @songs[key] if key.kind_of(Integer)
return @songs.find { |asong| asong.name == key}
end
end
songs = SongList.new
songfile = "songs.txt"
songfile.each do |line|
file, length, name, title = line.chomp.split(/\s*\|\s*/)
name.squeeze!(" ")
mins, secs = length.scan(/\d+/)
songs.append Song.new(title, name, mins.to_i*60+secs.to_i)
end
puts songs[1]
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.