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
lib/csv/table.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.1.3/lib/csv/table.rb, line 979
def to_a
array = [headers]
@table.each do |row|
array.push(row.fields) unless row.header_row?
end
array
end
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"]]