From: John T Date: 2001-02-22T15:28:19+09:00 Subject: [ruby-talk:11291] This is a multi-part message in MIME format. ------=_NextPart_000_0000_01C09CC7.960B93E0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit When i use DATA to access the data from within the file i get the following error. D:\LK\Ruby Prmg\21-2-01\ch 4\src\test.rb:113: uninitialized constant DATA(NameError) I am attachin the ruby file with this mail.. Please comment ------=_NextPart_000_0000_01C09CC7.960B93E0 Content-Type: application/octet-stream; name="test.rb" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="test.rb" class WordIndex=0A= def initialize=0A= @index =3D Hash.new(nil)=0A= end=0A= def index(anObject, *phrases)=0A= phrases.each do |aPhrase|=0A= aPhrase.scan /\w[-\w']+/ do |aWord| # extract each word=0A= aWord.downcase!=0A= @index[aWord] =3D [] if @index[aWord].nil?=0A= @index[aWord].push(anObject)=0A= end=0A= end=0A= end=0A= def lookup(aWord)=0A= @index[aWord.downcase]=0A= end=0A= end=0A= class Song=0A= include Comparable=0A= @@plays =3D 0=0A= attr_reader :name, :artist, :duration=0A= attr_writer :duration=0A= def initialize(name, artist, duration)=0A= @name =3D name=0A= @artist =3D artist=0A= @duration =3D duration=0A= @plays =3D 0=0A= end=0A= def to_s=0A= "Song: #{@name}--#{@artist} (#{@duration})"=0A= end=0A= def name=0A= @name=0A= end=0A= def artist=0A= @artist=0A= end=0A= def duration=0A= @duration=0A= end=0A= def duration=3D(newDuration)=0A= @duration =3D newDuration=0A= end=0A= def durationInMinutes=0A= @duration/60.0 # force floating point=0A= end=0A= def durationInMinutes=3D(value)=0A= @duration =3D (value*60).to_i=0A= end=0A= def play=0A= @plays +=3D 1=0A= @@plays +=3D 1=0A= "This song: #@plays plays. Total #@@plays plays."=0A= end=0A= def record=0A= "Recording..."=0A= end=0A= def inspect=0A= self.to_s=0A= end=0A= def <=3D>(other)=0A= self.duration <=3D> other.duration=0A= end=0A= end=0A= class SongList=0A= def initialize=0A= @songs =3D Array.new=0A= @index =3D WordIndex.new=0A= end=0A= def append(aSong)=0A= @songs.push(aSong)=0A= @index.index(aSong, aSong.name, aSong.artist)=0A= self=0A= end=0A= def deleteFirst=0A= @songs.shift=0A= end=0A= def deleteLast=0A= @songs.pop=0A= end=0A= def [](key)=0A= if key.kind_of?(Integer)=0A= @songs[key]=0A= else=0A= # ...=0A= end=0A= end=0A= def [](key)=0A= if key.kind_of?(Integer)=0A= return @songs[key]=0A= else=0A= for i in 0...@songs.length=0A= return @songs[i] if key =3D=3D @songs[i].name=0A= end=0A= end=0A= return nil=0A= end=0A= def [](key)=0A= if key.kind_of?(Integer)=0A= result =3D @songs[key]=0A= else=0A= result =3D @songs.find { |aSong| key =3D=3D aSong.name }=0A= end=0A= return result=0A= end=0A= def lookup(aWord)=0A= @index.lookup(aWord)=0A= end=0A= def createSearch(name, params)=0A= # ...=0A= end=0A= end =0A= songFile =3D DATA=0A= songs =3D SongList.new=0A= =0A= songFile.each do |line|=0A= file, length, name, title =3D line.chomp.split(/\s*\|\s*/)=0A= songs.append Song.new(title, name, length)=0A= end=0A= puts songs[1]=0A= __END__=0A= /jazz/j00132.mp3 | 3:45 | Fats Waller | Ain't Misbehavin'=0A= /jazz/j00319.mp3 | 2:58 | Louis Armstrong | Wonderful World=0A= /bgrass/bg0732.mp3| 4:09 | Strength in Numbers | Texas Red=0A= ------=_NextPart_000_0000_01C09CC7.960B93E0--