Created
April 25, 2013 17:24
-
-
Save mariapacana/5461508 to your computer and use it in GitHub Desktop.
Revised guessing game.
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(answer) | |
@answer = answer | |
end | |
def guess(guess) | |
@guess = guess | |
if guess > @answer | |
puts "high" | |
return :high | |
elsif guess < @answer | |
puts "low" | |
return :low | |
elsif guess == @answer | |
puts "correct" | |
return :correct | |
end | |
end | |
def solved? | |
@guess == @answer | |
if @guess == @answer | |
puts "yes" | |
else | |
puts "no" | |
end | |
end | |
end | |
game = GuessingGame.new(10) | |
game.guess(5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment