Method: CSV::Table#headers
- Defined in:
- lib/csv/table.rb
#headers ⇒ Object
:call-seq:
table.headers -> array_of_headers
Returns a new Array containing the String headers for the table.
If the table is not empty, returns the headers from the first row:
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:
table.delete(0)
table.headers # => ["Foo", "Bar"]
360 361 362 363 364 365 366 |
# File 'lib/csv/table.rb', line 360 def headers if @table.empty? @headers.dup else @table.first.headers end end |