I have to create 28 arrays named the following:
all_questions_1 = []
all_questions_2 = []
...
all_questions_28 = []
I do not want to create them manually so I am trying to figure out how to do so dynamically with a lot of failed attempts.
I checked the previous questions with little success.
Ruby dynamically naming arrays
After reading the comment I added this additional explanation on the why I asked this question
What I am trying to solve is a problem I have inside a Ruby_on_Rails controller for an custom action called replies
The action is the following:
def replies
@project = Project.find(params[:project_id])
@paper = Paper.find(params[:paper_id])
@replies = Question.where("project_id = ? AND paper_id = ?", params[:project_id], params[:paper_id])
end
@replies gives back a long object containing all the replies on each paper contained in a project.
Therefore, one paper can be answered by multiple users. Each paper is inside a project. Each project contains several papers.
(The user can answer all the 28 questions with: NA, NO, MAYBE, YES which I translated to "-1", "0", "0.5", "1")
This is what the object @replies gives me back.

Now, once I have that. I have to map all the 28 replies/questions. I want to do the following.
@replies.map do |reply|
all_question_1 << reply.question_1.to_i
end
And I want to do it 28 times (there are 28 questions), that is why I need 28 arrays. I am doing it because I want the possible answers which are strings "-1", "0", "0.5", "1" to be changed into numbers -1, 0, 0,5, 1
Once dode that, I want to count for each question (all_question_1, all_question_2... all_question_28) how many questions with -1 or 0 or 0.5 or 1 are contained.
TO SUM UP:
I need to build the following code 28 times changing the name_of_array_[NUMBER] from 1 to 28:
all_question_1 = []
@replies.map do |reply|
all_question_1 << reply.question_1.to_i
end
na_question_1 = all_question_1.count(-1)
no_question_1 = all_question_1.count(0)
maybe_question_1 = all_question_1.count(0.5)
yes_question_1 = all_question_1.count(1)
len_question_1 = all_question_1.length
I do not want to do it manually, so I was wondering if there is a way to dynamically change the _NUMBER from 1 to 28.