# Simple class question - new to ruby on rails

**URL:** <https://www.ruby-forum.com/t/simple-class-question-new-to-ruby-on-rails/191380>\
**Category:** Rails\
**Created:** [July 11, 2010, 9:40am UTC](https://www.ruby-forum.com/t/simple-class-question-new-to-ruby-on-rails/191380 "2010-07-11T09:40:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![superwick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/46a35a/32.png) [@superwick](https://www.ruby-forum.com/u/superwick)\
**Post date:** [July 11, 2010, 9:40am UTC](https://www.ruby-forum.com/t/simple-class-question-new-to-ruby-on-rails/191380/1 "2010-07-11T09:40:23Z")

</div>

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]

---

<div class="post-metadata">

**Author:** ![superwick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/46a35a/32.png) [@superwick](https://www.ruby-forum.com/u/superwick)\
**Post date:** [July 11, 2010, 12:47pm UTC](https://www.ruby-forum.com/t/simple-class-question-new-to-ruby-on-rails/191380/2 "2010-07-11T12:47:50Z")

</div>

Well from the looks of it your problem is this

songfile = “songs.txt”  
songfile.each do |line|

You are not opening the file “songs.txt” which is what you want to do I  
believe. Take a look at this  
[http://ruby-doc.org/core/classes/IO.html#M002255](http://ruby-doc.org/core/classes/IO.html#M002255)
