Is it possible to create multiple variables by iterating over an array?
For example, say I had an array called numbers = [1,2,3,4,5] and I wanted to create a series of variables called number_1, number_2,...,number_5 each equal to their respective index in the numbers array (e.g. number_1 = 1, number_2 = 2, etc.).
I tried something along the lines of the following:
numbers.each_with_index do |num, index|
number_"#{index+1}" = num
end
But that failed.
Essentially, I would like for the iterating process to automate creating and assigning values to variables.
Thank you.
number_1give you thatnumbers[0]doesn't?