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.
My terrible attempt at refactoring.On my first and unpublished attempt I tried to fix everything at once. I got halfway through moving the model into a class and expanding much of the functionality before totally losing track of where I was. Seriously kids don't apply functionality without a test. My second and successful attempt used much more involved note taking and testing of each new feature.
Rspec now running.First I made sure that the original basic tests ran on the new model I had made. Well, I mean first I made sure they didn't run, but that they later did, and anyways you know how it works.
Moved rspec helper code into .rspec file.This was also a good opportunity for me to take the time to clear up some loose ends from over a month ago such as making a .rspec file and properly applying stubbing.
Decided that all screen printing work belonged in app.My initial impulse was to move _every thing_ into the class. Then I decided that with the extremly limited degree to which I could honor the concept of MVC in such a limited app that it was not the right move to have the class Numberguesser know anything about the screen.
Moved input and standard comparison into class. Left reporting responsibilites in the app. Added new syntax to app in order to obtain, evaluate, and report on guess.All these commits have to do with pulling apart the screen printing functionality from the knowing about number equivalency.
Radically shortened check_guess by relying on Ruby's logic processing and returns.
This is my favorite trick this week of shortening a method that checks for equivalency
if @input == @standard<br/> true<br/> else<br> false<br/> end
@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 methodsMOAR 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.