Class: VariableReassignmentQuestion
- Inherits:
-
FollowUpQuestion
- Object
- Question
- FollowUpQuestion
- VariableReassignmentQuestion
- Defined in:
- lib/battleroom/models/variable_reassignment_question.rb
Instance Attribute Summary collapse
-
#toggled_boolean ⇒ Object
Returns the value of attribute toggled_boolean.
Attributes inherited from FollowUpQuestion
Attributes inherited from Question
#answer_value, #data, #data_structure, #data_structure_class, #evaluation_scope, #explanation, #input_mechanism, #user_input, #variable_name, #variable_value
Instance Method Summary collapse
- #evaluate_variable_reassignment_input ⇒ Object
-
#initialize(evaluation_scope, original_question) ⇒ VariableReassignmentQuestion
constructor
A new instance of VariableReassignmentQuestion.
- #print_variable_reassignment_prompt ⇒ Object
Methods inherited from Question
#congratulation_sequence, #enter_evaluation_loop, generate_question, #get_input, #handle_syntax_error_exceptions
Constructor Details
#initialize(evaluation_scope, original_question) ⇒ VariableReassignmentQuestion
Returns a new instance of VariableReassignmentQuestion.
7 8 9 10 11 12 |
# File 'lib/battleroom/models/variable_reassignment_question.rb', line 7 def initialize(evaluation_scope, original_question) super(evaluation_scope, original_question) @toggled_boolean = !(original_question.variable_value) print_variable_reassignment_prompt evaluate_variable_reassignment_input end |
Instance Attribute Details
#toggled_boolean ⇒ Object
Returns the value of attribute toggled_boolean.
5 6 7 |
# File 'lib/battleroom/models/variable_reassignment_question.rb', line 5 def toggled_boolean @toggled_boolean end |
Instance Method Details
#evaluate_variable_reassignment_input ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/battleroom/models/variable_reassignment_question.rb', line 18 def evaluate_variable_reassignment_input enter_evaluation_loop do |user_submission| input = user_submission evaluation_scope.eval(input) if (evaluation_scope.eval(original_question.variable_name) == toggled_boolean) true else battleprint "Nope. Try again.".red end end end |
#print_variable_reassignment_prompt ⇒ Object
14 15 16 |
# File 'lib/battleroom/models/variable_reassignment_question.rb', line 14 def print_variable_reassignment_prompt battleprint "Times have changed! Reassign ".blue + original_question.variable_name.yellow + " to the Boolean value ".blue + toggled_boolean.to_s.yellow + ".\n".blue end |