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#headers
table.headers → array_of_headers
lib/csv/table.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.1.3/lib/csv/table.rb, line 360
def headers
if @table.empty?
@headers.dup
else
@table.first.headers
end
end
Returns a new Array containing the String headers for the table.
If the table is not empty, returns the headers from the first row:
Example
rows = [ CSV::Row.new(['Foo', 'Bar'], []), CSV::Row.new(['FOO', 'BAR'], []), CSV::Row.new(['foo', 'bar'], []), ] table = CSV::Table.new(rows) table.headers # => ["Foo", "Bar"] table.delete(0) table.headers # => ["FOO", "BAR"] table.delete(0) table.headers # => ["foo", "bar"]
If the table is empty, returns a copy of the headers in the table itself:
Example
table.delete(0) table.headers # => ["Foo", "Bar"]