Skip to content

Instantly share code, notes, and snippets.

@TrevMcKendrick
Created October 11, 2013 15:56
Show Gist options
  • Save TrevMcKendrick/6937261 to your computer and use it in GitHub Desktop.
Save TrevMcKendrick/6937261 to your computer and use it in GitHub Desktop.
class Jukebox
attr_accessor :songs, :desire, :current_song #:song_hash
def initialize(songs)
@songs = songs
#@song_hash = {}
help
end
def display
puts "\nI'm ready for your command. Type help for, well, help!"
input
end
def help
puts "\nHere's the choices to use the jukebox: \n Play!\n List!\n Exit"
input
end
def play
puts "Which song would you like?"
self.current_song = gets.chomp
if self.songs.include?(self.current_song)
puts "Now playing:\n*#{self.current_song}*"
else
puts "That song is not available, sorry!"
end
end
def list
puts self.songs
end
def exit
puts "Let's get out of here!"
end
def input
self.desire = gets.chomp.downcase.strip
parse
end
def parse
case self.desire
when "help"
help
when "play"
play
display
when "list"
list
display
when "exit"
exit
display
end
end
end
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"
]
j = Jukebox.new(songs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment