Skip to content

Instantly share code, notes, and snippets.

@scarow
Last active December 19, 2015 04:28
Show Gist options
  • Select an option

  • Save scarow/5897043 to your computer and use it in GitHub Desktop.

Select an option

Save scarow/5897043 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(num_guessed)
@num_guessed = num_guessed
if @num_guessed > @answer
:high
elsif @num_guessed < @answer
:low
elsif @num_guessed == @answer
:correct
end
end
def solved?
@num_guessed == @answer
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment