Class: Guess
Overview
Class to model answers that are guesses
Instance Attribute Summary collapse
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#word_to_guess ⇒ Object
readonly
Returns the value of attribute word_to_guess.
Attributes inherited from Answer
Instance Method Summary collapse
-
#initialize(answer, word_to_guess) ⇒ Guess
constructor
A new instance of Guess.
- #valid? ⇒ Boolean
Methods inherited from Answer
Constructor Details
#initialize(answer, word_to_guess) ⇒ Guess
Returns a new instance of Guess.
10 11 12 13 14 |
# File 'lib/guess.rb', line 10 def initialize(answer, word_to_guess) super(answer) @word_to_guess = word_to_guess.word valid? end |
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors.
8 9 10 |
# File 'lib/guess.rb', line 8 def errors @errors end |
#word_to_guess ⇒ Object (readonly)
Returns the value of attribute word_to_guess.
7 8 9 |
# File 'lib/guess.rb', line 7 def word_to_guess @word_to_guess end |
Instance Method Details
#valid? ⇒ Boolean
16 17 18 19 20 21 |
# File 'lib/guess.rb', line 16 def valid? self.errors = [] errors << 'Must be a letter' unless letter? errors << 'Must be a single letter or guessing the full word' unless single_letter? || full_word_guess? errors.empty? end |