Reputation: 1060
I have an array of arrays:
array = [
[1,2,3],
[4,5,6],
[7,8,9]
]
How would I iterate over each array and print them out individually, without using map
?
Something like
array.each do |a|
puts a
end
> [1,2,3]
> [4,5,6]
> [7,8,9]
Upvotes: 0
Views: 44
Reputation: 80065
The to_s
method of Array gives a string representation.
array = [ [1,2,3],
[4,5,6],
[7,8,9]]
array.each do |a|
puts a.to_s #or just: p a
end
Output
[1, 2, 3]
[4, 5, 6]
[7, 8, 9]
Upvotes: 3