Skip to content

Instantly share code, notes, and snippets.

@joshrowley
Created October 18, 2012 00:07
Show Gist options
  • Save joshrowley/3909117 to your computer and use it in GitHub Desktop.
Save joshrowley/3909117 to your computer and use it in GitHub Desktop.
Jukebox
songs = [
"The Phoenix - 1901",
"Tokyo Police Club - Wait Up",
"Sufjan Stevens - Too Much",
"The Naked and the Famous - Young Blood",
"(Far From) Home - Tiga",
"The Cults - Abducted",
"The Phoenix - Consolation Prizes"
]
def help
puts "To see all songs and their corresponding track numbers, use list"
puts "To play a song, use play <track number>"
puts "For example, to play Abducted by The Cults, use play 5"
puts "To exit, use exit"
end
def play(songs, song_selection)
puts "Playing #{songs[song_selection]}"
end
def list(songs)
songs.each_with_index { |song, index|
puts "#{index} => #{song}"
}
end
exit = false
puts "Hi, welcome to Jukebox."
while exit == false
print "Enter a command, or type help: "
command = gets.downcase.strip.split
case command.first
when "help"
help
when "play"
song_selection = command[1].to_i
play(songs, song_selection)
when "list"
list songs
when "exit"
exit = true
else
puts "Sorry, that's not a valid command, type help if you need assistance."
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment