Skip to content

Instantly share code, notes, and snippets.

@torsday
Last active December 13, 2015 19:38
Show Gist options
  • Save torsday/4963876 to your computer and use it in GitHub Desktop.
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.
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