I am trying to learn Ruby, and arrays are giving me some trouble.
I have input that I flatten down to the pattern "name, number, name, number". I then want to make an array of 2-element arrays, each containing a name and the next number.
When I push these 2-element arrays into another array the seem to automatically flatten to a 0-dimensional array. What I want is the final array to be of size [N/2][2], N being number of names, or numbers in the input.
The puts with the comment does not happen until all of the elements from the pairs array has been printed, so it looks like this:
Name
1
Name
2
Name
3
When I expected this:
Name
1
Name
2
Name
3
I guess my questions are:
- How do I put arrays inside an array, to make a jagged one?
- How do I keep track of how many dimensions my arrays are in Ruby? It's so much easier when you have to declare a size.