Created
May 14, 2013 18:56
-
-
Save brettsanders/5578482 to your computer and use it in GitHub Desktop.
guessing game dbc exercise
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 GuessingGame | |
def initialize(guess) | |
@answer = rand(guess) | |
@guess = nil | |
end | |
def solved? | |
@guess == @answer | |
end | |
def guess(guess) | |
@guess = guess | |
case | |
when guess > @answer | |
:high | |
when guess < @answer | |
:low | |
when guess == @answer | |
:correct | |
end | |
end | |
end | |
game = GuessingGame.new(10) | |
p game | |
p game.solved? # => false | |
p game | |
p game.guess(5) # => :low | |
p game |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment