Topic: Method from within other method
I am trying to call question_and_annos from within questions_and_answers and pass "complete_question" as an argument. I get the error undefined local variable or method `complete_question' for #<Question:0x103228d10>
Excuse the very basic level of code as I am still a beginner (any suggestions are appreciated though).
Here are the 2 methods:
def question_and_annos(x)
answer_list = [
[self.incorrect_ans_1, self.incorrect_anno_1],
[self.incorrect_ans_2, self.incorrect_anno_2],
[self.incorrect_ans_3, self.incorrect_anno_3],
[self.incorrect_ans_4, self.incorrect_anno_4]
].shuffle
# Randomly insert the correct answer and response into the pre-shuffled array.
random_insert = rand(4)
answer_list.insert(random_insert,["#{correct_ans_1} *",self.correct_anno])
# Create Hash of virtual attributes.
# Convert from array to string to display in view "questions.show.html.erb".
shuffled = {
:complete_question => "#{question} \r\r\r A. #{answer_list[0][0]}\r B. #{answer_list[1][0]}\r C. #{answer_list[2][0]}\r D. #{answer_list[3][0]}\r E. #{answer_list[4][0]}\r",
:anno_a => answer_list[0][1],
:anno_b => answer_list[1][1],
:anno_c => answer_list[2][1],
:anno_d => answer_list[3][1],
:anno_e => answer_list[4][1]
}
if x == "complete_question": result = shuffled[complete_question]
elsif x == "anno_1": result = shuffled[anno_1]
elsif x == "anno_2": result = shuffled[anno_2]
elsif x == "anno_3": result = shuffled[anno_3]
elsif x == "anno_4": result = shuffled[anno_4]
elsif x == "anno_5": result = shuffled[anno_5]
end
end
def question_with_answers
x = question_and_annos(complete_question)
end
Thanks,
DC