Skip to content

Instantly share code, notes, and snippets.

@Jaltman429
Created June 10, 2013 17:57
Show Gist options
  • Save Jaltman429/5750855 to your computer and use it in GitHub Desktop.
Save Jaltman429/5750855 to your computer and use it in GitHub Desktop.
Jukebox.rb (as a class)
# jukebox.rb
class Jukebox
@@jukeboxes = []
def initialize (name)
@@on = true
@name = name
@user_tracks = []
@user_tracks << @name
@@jukeboxes << @user_tracks
puts "You are now on user #{name}"
end
def jukehistory
puts @@jukeboxes
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"
]
# list, play, help, exit
def list
if @@on
SONGS.each.with_index do |song, index|
puts (index + 1).to_s + ". " + song
end
else
puts "please turn the Jukebox on first, #{@name}"
return
end
end
def play
if @@on
puts "Please select the song number you would like to play"
number = gets.strip.to_i
number -= 1
puts "You are currently playing #{SONGS[number]}"
@user_tracks << SONGS[number]
else
puts "please turn the Jukebox on first, durr"
return
end
end
def help
if @@on
puts "to see all available songs type 'jukebox.list'"
puts "to play a song type its index number from the list"
puts "to turn the jukebox off type exit"
else
puts "please turn the Jukebox on first, durr"
return
end
end
def exit
@@on = false
end
end
#instantiate class
# jukebox = Jukebox.new('jack')
# play = jukebox.play
# play = jukebox.play
# play = jukebox.play
# jukehistory = jukebox.jukehistory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment