Skip to content

Instantly share code, notes, and snippets.

@kmandreza
Created January 20, 2013 18:35
Show Gist options
  • Save kmandreza/4580553 to your computer and use it in GitHub Desktop.
Save kmandreza/4580553 to your computer and use it in GitHub Desktop.
Create a GuessingGame class which is initialized with an integer called answer. Define an instance method GuessingGame#guess which takes an integer called guess as its input. guess should return the symbol :high if the guess is larger than the answer, :correct if the guess is equal to the answer, and :low if the guess is lower than the answer. D…
class GuessingGame
def initialize(answer)
@answer = answer
end
def guess(guess)
@guess = guess
if guess > @answer
return :high
elsif guess == @answer
return :correct
else guess < @answer
return :low
end
end
def solved?
@guess == @answer
end
# Make sure you define the other required methods, too
end
#lynda.com - instance methethod, initialize method, symbols
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment