Refactor Friday Part I

I went back to refactor one of the earliest homework assignments that we were given at the Flatiron School, which is the Number Guesser. Although it was all on one page and the tests totally didn't pass, I wasn't too displeased with how it has aged. Hardly fine wine, but at least not compost either. I ended up with a very long commit history that I tried to make into the general outline of my blogpost.

This:
def checkforequivalency

if @input == @standard<br/>
  true<br/>
else<br>
  false<br/>
 end


Becomes:

def equivalent?
@input == @standard

  • Had to unchain method calls as .guess returns a string. Whaaaat?! The "s" in gets means string. ^%$#!!!

  • realized that gets converts input into string. Included to_i to counter that and a validity check to recognize post to_i strings.

  • Changed method name to refelct true false response. One of the few teachable moments here. Having explicit names that both indicate the work it does as well as the return it gives makes for friendlier code. Noticed that response was missing the interpolated value when I ran the program. Added it back in.

  • Added tests to methods MOAR TESTS!!!

  • Got up to get a cup of tea. Thought of more features. Didn't yet decide if they were app or class features. Proud of myself that I resisted dropping in three half-baked def's. Wrote notes to myself that I wanted to get back to making these.

  • Added loop to allow repeated guesses. can end the game with exit.

  • Added exit test and higher/lower functionality. New functionality in the app and in the class now that I know what goes where.