Class: VariableReassignmentQuestion

Inherits:
FollowUpQuestion show all
Defined in:
lib/battleroom/models/variable_reassignment_question.rb

Instance Attribute Summary collapse

Attributes inherited from FollowUpQuestion

#original_question

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

Methods inherited from FollowUpQuestion

#initialize

Methods inherited from Question

#congratulation_sequence, #enter_evaluation_loop, generate_question, #get_input, #handle_syntax_error_exceptions, #initialize

Constructor Details

This class inherits a constructor from FollowUpQuestion

Instance Attribute Details

#toggled_booleanObject

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_inputObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/battleroom/models/variable_reassignment_question.rb', line 17

def evaluate_variable_reassignment_input
  enter_evaluation_loop do |user_submission|
    input = user_submission
    begin
      evaluation_scope.eval(input)
      if (evaluation_scope.eval(original_question.variable_name) == toggled_boolean)
        true
      else
        battleprint "Nope. Try again.".red
      end
    rescue NameError, NoMethodError => e
      print_colorized_error_prompt(e)
    end
  end
end

#post_initializeObject



7
8
9
10
11
# File 'lib/battleroom/models/variable_reassignment_question.rb', line 7

def post_initialize
  @toggled_boolean = !(original_question.variable_value)
  print_variable_reassignment_prompt
  evaluate_variable_reassignment_input
end


13
14
15
# File 'lib/battleroom/models/variable_reassignment_question.rb', line 13

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