Skip to content

Instantly share code, notes, and snippets.

@javierg
Created February 8, 2013 23:21
Show Gist options
  • Select an option

  • Save javierg/4742784 to your computer and use it in GitHub Desktop.

Select an option

Save javierg/4742784 to your computer and use it in GitHub Desktop.

Revisions

  1. javierg revised this gist Feb 8, 2013. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -16,7 +16,6 @@ class FortuneTellerMachine

    def pending
    puts REQUEST
    puts self.coins
    self.coins += gets.to_i
    if self.coins > COST
    give_change
  2. javierg created this gist Feb 8, 2013.
    62 changes: 62 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,62 @@
    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
    puts self.coins
    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