Skip to content

Instantly share code, notes, and snippets.

@javierg
Created February 8, 2013 23:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save javierg/4742784 to your computer and use it in GitHub Desktop.
Save javierg/4742784 to your computer and use it in GitHub Desktop.
Fortune Teller Machine
class FortuneTellerMachine
WELCOME = "Hola ¿Quiéres saber tu fortuna?"
REQUEST = "Fortuna por monedas, yo quiero yo quiero monedas (2): "
CHANGE_BACK = "Here is your change"
COST = 2
def initialize
clear
end
def start
puts WELCOME
pending
end
def pending
puts REQUEST
self.coins += gets.to_i
if self.coins > COST
give_change
elsif self.coins == COST
finish
else
pending
end
end
def give_change
change = self.coins - COST
puts [CHANGE_BACK, change].join("")
puts
finish
end
def finish
puts fortune.shuffle.first
clear
end
def clear
self.coins = 0
end
def coins= amount
@coins = amount
end
def coins
@coins
end
def fortune
[
"You only need look to your own reflection for inspiration. Because you are Beautiful!",
"Rivers need springs.",
"Good news from afar may bring you a welcome visitor.",
"When all else seems to fail, smile for today and just love someone.",
"When you look down, all you see is dirt, so keep looking up.",
]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment