Skip to content

Instantly share code, notes, and snippets.

@mariapacana
Created April 25, 2013 17:24
Show Gist options
  • Save mariapacana/5461508 to your computer and use it in GitHub Desktop.
Save mariapacana/5461508 to your computer and use it in GitHub Desktop.
Revised guessing game.
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