Unable to search for a string in an Array : <p>The Program is designed to read in album information from a .txt file, once the user inputs their desired track, the program checks an array to see if it contains that track. I have been successfully able to read the tracks into the array, but my program cannot identify if a string lies in this array or not.</p>

<p>The Ruby File</p>

<pre><code>require './input_functions'
module Genre
  POP, CLASSIC, JAZZ, ROCK = *1..4
end

$genre_names = ['Null', 'Pop', 'Classic', 'Jazz', 'Rock']

class Album
    attr_accessor :title, :artist, :genre, :tracks

    def initialize (title, artist, genre)
        # insert lines here
        @title = title
        @artist = artist
        @genre = genre  
    end
end

class Track
    attr_accessor :name, :location
    def initialize (name, location)
        @name = name
        @location = location
    end
end

def read_track(music_file)
    track_name = music_file.gets
    track_location = music_file.gets
    track = Track.new(track_name, track_location)
end


def read_tracks(music_file)
    tracks = Array.new
    count = music_file.gets.to_i
    index = 0
while index &lt; count
    tracks &lt;&lt; read_track(music_file)
    index += 1
end
    tracks
end

def print_tracks(tracks)
    index = 0
    while (index &lt; tracks.length)
    puts 'Track Number ' + index.to_s + ' is:'
    print_track(tracks[index])

    index = index + 1
end
    tracks
end

def read_album music_file
    album_artist = music_file.gets
    album_title = music_file.gets
    album_genre = music_file.gets
    album = Album.new(album_title, album_artist, album_genre)
    album
end


def print_album album

    puts 'Album title is ' + album.title.to_s
    puts 'Album artist is ' + album.artist.to_s
    puts 'Genre is ' + album.genre.to_s
    puts $genre_names[album.genre.to_i]
    # print out the tracks
    puts 'Tracks are ' + print_tracks(album.tracks).to_s

end


def print_track track
  puts('Track title is: ' + track.name.to_s)
    puts('Track file location is: ' + track.location.to_s)
end

** This is where I am having my problem
# search for track by name.
# Returns the index of the track or -1 if not found
def search_for_track_name(tracks, search_string)
    search_string = gets.chomp
    index = 0
while (index &lt; tracks.length)
    tracks.include?(search_string)
    index = index + 1
end
    if tracks.include?(search_string)
        return index
    else
        index = -1

    end
    return index
end


# Reads in an Album from a file and then prints all the album
# to the terminal

def main

  music_file = File.new("album.txt", "r")
    if music_file
    album = read_album(music_file)
    album.tracks = read_tracks(music_file)
  music_file.close()
    end

  search_string = read_string("Enter the track name you wish to find: ")
  index = search_for_track_name(album.tracks, search_string)
  if index.to_i &gt; -1
    puts "Found " + album.tracks[index].name + " at " + index.to_s
  else
    puts "Entry not Found"
  end
end
main

</code></pre>

<p>This is the .txt file</p>

<pre><code>Neil Diamond
Greatest Hits
1
3
Crackling Rose
sounds/01-Cracklin-rose.wav
Soolaimon
sounds/06-Soolaimon.wav
Sweet Caroline
sounds/20-Sweet_Caroline.wav

</code></pre>

<p>When the user enters "Sweet Caroline", the program should return that it has found the track, instead it does:</p>

<pre><code>Enter the track name you wish to find:
Sweet Caroline

Entry not Found

Tracks are [#&lt;Track:0x000000000331be58 @name="Crackling Rose\n", @location="sounds/01-Cracklin-rose.wav\n"&gt;, #&lt;Track:0x000000000331bdb8 @name="Soolaimon\n", @location="sounds/06-Soolaimon.wav\n"&gt;, #&lt;Track:0x000000000331bd18 @name="Sweet Caroline\n", @location="sounds/20-Sweet_Caroline.wav\n"&gt;]

</code></pre>
