Created
June 16, 2013 20:32
-
-
Save surrealdetective/5793317 to your computer and use it in GitHub Desktop.
jukebox as an object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Jukebox | |
attr_accessor :songs | |
def welcome | |
puts "Welcome to jukebox." | |
end | |
def instruction | |
puts "What would you like to do? Please enter list, play, help, or exit" | |
instruction = gets.downcase.chomp | |
if instruction == "exit" | |
self.exit | |
elsif instruction == "play" | |
self.play | |
elsif instruction == "list" | |
self.list | |
elsif instruction == "help" | |
self.help | |
end | |
end | |
def list | |
@songs.each_with_index do |song, index| | |
puts "Press #{index+1} \t #{song}" | |
end | |
self.instruction | |
end | |
#? why does adding a self.play on line 36 help exit work immediately? | |
def play | |
puts "Which song number would you like to play?" | |
request=gets.chomp.strip.to_i | |
if request > @songs.length - 1 || request <= 0 | |
puts "Please enter a number from 1 through #{@songs.length}" | |
return self.play | |
else | |
puts "Jukebox is now playing #{@songs[request-1]}" | |
end | |
self.instruction | |
end | |
#! initialize determines what must be passed into the class to create it | |
def initialize(songs) | |
self.songs = songs | |
self.welcome | |
self.instruction | |
# self.setSongs | |
# puts self.getSongs | |
#/*this should call the welcome method automatically. | |
#/*this should call the instruction method | |
end | |
def help | |
puts "[Help]" | |
puts "You have the following options:" | |
puts "[play] to play your song." | |
puts "[list] to list all songs on the jukebox." | |
puts "[exit] to exit the jukebox." | |
self.instruction | |
end | |
def exit | |
return puts "Goodbye :)" | |
#not sure how to make program start or exit. | |
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" | |
] | |
Jukebox.new(songs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment