Skip to content

End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

CSV::Table#to_a

table.to_a → array_of_arrays

Returns the table as an Array of Arrays; the headers are in the first row:

Example
source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
table = CSV.parse(source, headers: true)
table.to_a # => [["Name", "Value"], ["foo", "0"], ["bar", "1"], ["baz", "2"]]
See also #push #to_csv #inspect #to_s also in 3.3 · 3.2 · 3.0