user1762229 user1762229 - 3 months ago 17
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"]
["John,"Smith"]
["Kevin","Will"]
["Stanley","George"]

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