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
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]