Created
January 20, 2013 18:35
-
-
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…
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 | |
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