user1762229 user1762229 - 2 months ago 7x
Ruby Question

placing sub arrays in neat rows

I am currently working on a large array of names:

large_array = ["Bob","Joel","John","Smith","Kevin","Will","Stanley","George"] #and so on

I split it into sub arrays like so:

large_array.each_slice(2).to_a #=> [["Bob", "Joel"],["John,"Smith"],["Kevin", "Will"],["Stanley","George"]]

My question is how do I make the sub arrays appear neatly on top of each other in rows like this:

["Bob", "Joel"]

large_array.each_slice(2) {|a| puts a.inspect}
# ["Bob", "Joel"]
# ["John", "Smith"]
# ["Kevin", "Will"]
# ["Stanley", "George"]
# => nil