Conversation
| # index is entirely based on the number of misses | ||
| def get_state index | ||
| @states[index] | ||
| end |
There was a problem hiding this comment.
The general practice on our team has been to avoid comments when possible. Here for instance, renaming the variable to from index to number_of_misses would do the trick.
|
|
||
| def get_word | ||
| @word | ||
| end |
There was a problem hiding this comment.
check out attr_reader (and attr_accessor while you're at it) in the ruby documentation.
There was a problem hiding this comment.
Once, I finish up the challenges, I'll be going back through to refactor everything. I've been learning quite a bit by going straight through these, and that is one of the things I've picked up on (thanks to RuboCop).
| end | ||
|
|
||
| def get_lines guesses | ||
| @word.chars.map{ |char| |
There was a problem hiding this comment.
Once you've got the reader method in place, then @word can become just word here.
| end | ||
|
|
||
| def input_is_valid? input | ||
| return !!(input =~ /[a-z]/i) && (input.length == 1) |
There was a problem hiding this comment.
standard ruby style is to avoid using the return keyword unless it's an early return
There was a problem hiding this comment.
Another thing I've realized with further challenges. Will fix soon. Thanks.
| @guesses = [] | ||
| @misses = [] | ||
| @words = WordFactory.get_words | ||
| @screen = Screen.new |
There was a problem hiding this comment.
as mentioned below, some attr_accessors would help here.
There was a problem hiding this comment.
Most of these are meant to be private, so is there a reason to assign accessors?
There was a problem hiding this comment.
Ok, I see what you're thinking. In the code I've seen here, I'd say that most ruby-folks would use attr_readers or attr_accessors whenever they're referring to instance variables, but maybe there is not much reason to in cases like this. I mean, there is always the aspect of changing everything to a custom getter/setter easily, but that honestly doesn't happen very often.
There was a problem hiding this comment.
You can define attr_readers and attr_accessors under a call to private. I recommend always using the methods. Ruby has this stupid behavior: @ivar_with_typo #=> nil. Method calls with typos will raise an exception.
No description provided.