Method: CSV::Table#to_a

Defined in:
lib/csv/table.rb

#to_aObject

:call-seq:

table.to_a -> array_of_arrays

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

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"]]


978
979
980
981
982
983
984
985
# File 'lib/csv/table.rb', line 978

def to_a
  array = [headers]
  @table.each do |row|
    array.push(row.fields) unless row.header_row?
  end

  array
end