Last active
December 16, 2015 22:09
-
-
Save Rleahy22/5504781 to your computer and use it in GitHub Desktop.
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) | |
end | |
def guess(guess) | |
@last_guess = guess | |
if guess == @answer | |
return :correct | |
elsif guess < @answer | |
return :low | |
elsif guess > @answer | |
return :high | |
end | |
end | |
def solved? | |
if @last_guess != @answer | |
return false | |
else | |
return true | |
end | |
end | |
end | |
new_game = GuessingGame.new(2) | |
p new_game.guess(0) | |
p new_game.solved? | |
p new_game.guess(2) | |
p new_game.solved? | |
p new_game.guess(1) | |
p new_game.solved? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment