Class: NestedDataStructureAccessQuestion

Inherits:
DataStructureAccessQuestion show all
Defined in:
lib/battleroom/models/nested_data_structure_access_question.rb

Instance Attribute Summary collapse

Attributes inherited from DataStructureQuestion

#data_structure, #hint, #possible_assignments

Attributes inherited from Question

#answer_value, #data, #data_structure, #data_structure_class, #evaluation_scope, #explanation, #type, #variable_name, #variable_value

Instance Method Summary collapse

Methods inherited from DataStructureAccessQuestion

#evaluate_data_structure_access_input, #print_data_structure_access_prompt

Methods inherited from DataStructureQuestion

#convert_keys_to_strings, #cull_hash_to_valid_size_for_output, #find_number_of_boolean_values_in_hash

Methods inherited from Question

#enter_evaluation_loop, generate_question

Constructor Details

#initialize(eval_scope) ⇒ NestedDataStructureAccessQuestion



9
10
11
12
13
14
15
16
17
# File 'lib/battleroom/models/nested_data_structure_access_question.rb', line 9

def initialize(eval_scope)
  super(eval_scope)
  if data_structure.class == Array
    self.inner_hash = data_structure.sample
    self.answer_value = inner_hash[inner_hash.keys.sample]
  else
    self.answer_value = data_structure[data_structure.keys.sample]
  end
end

Instance Attribute Details

#inner_arrayObject

Returns the value of attribute inner_array.



5
6
7
# File 'lib/battleroom/models/nested_data_structure_access_question.rb', line 5

def inner_array
  @inner_array
end

#inner_hashObject

Returns the value of attribute inner_hash.



5
6
7
# File 'lib/battleroom/models/nested_data_structure_access_question.rb', line 5

def inner_hash
  @inner_hash
end