Last active
December 13, 2015 19:38
-
-
Save torsday/4963876 to your computer and use it in GitHub Desktop.
Here is the corrected version. My mistake was returning a value before toggling @solved for one of the branches. Thanks to Sean for seeing what my eyes were glazing over.
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 | |
# this is just a crapshoot, doesn't seem to help or hinder | |
attr_accessor :solved | |
attr_accessor :answer_int | |
def initialize(answer_int) | |
@answer = answer_int | |
@solved = false | |
end | |
def guess(guess_int) | |
# return :low, :correct, or :high | |
if(@answer < guess_int) | |
@solved = false | |
return :high | |
elsif (guess_int == @answer) | |
@solved = true | |
return :correct | |
elsif (guess_int < @answer) | |
@solved = false | |
return :low | |
else | |
@solved = false | |
raise "guess_int not registering as an int" | |
end | |
end | |
def solved? | |
# returns true or false | |
@solved | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment