Reputation: 1948
I have an array of arrays that is currently printing each object in the array on its own line. The master array holds many different people inside of it. Each person has 5 different objects stored to them (e.g. Last Name, First Name, DOB.. etc)
Kournikova
Anna
F
6/3/1975
Red
Hingis
Martina
F
4/2/1979
Green
Seles
Monica
F
12/2/1973
Black
What I'm trying to do is print out each person and their corresponding objects on one line, per person.
Does anyone have a solution for this? Additionally, the output should not contain array brackets ([]
) or commas. I'm wondering if it will simply need to be a string, or if there is something I am missing.
Some of my code below:
space_array = [split_space[0],split_space[1],split_space[3],new_date,split_space[5]]
master << space_array
puts master
The ideal output would be something like this:
Kournikova Anna F 6/3/1975 Red
Hingis Martina F 4/2/1979 Green
Seles Monica F 12/2/1973 Black
Upvotes: 13
Views: 25033
Reputation: 66837
You can just iterate over the outer array and join
the inner arrays into a string. Since you provide no example data ready for copying and pasting, here's some example code I made up:
outer_array.each { |inner| puts inner.join(' ') }
Upvotes: 3
Reputation: 604
The method puts will automatically put a new line. Use print instead to print the text out with no new line.
Or if you want, you can use the join function.
['a', 'b', 'c'].join(' ')
=> 'a b c'
Upvotes: 12