Skip to content

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

class method

CSV::Row.new

CSV::Row.new(headers, fields, header_row = false) → csv_row

Returns the new CSV::Row instance constructed from arguments headers and fields; both should be Arrays; note that the fields need not be Strings:

Example
row = CSV::Row.new(['Name', 'Value'], ['foo', 0])
row # => #<CSV::Row "Name":"foo" "Value":0>

If the Array lengths are different, the shorter is nil-filled:

Example
row = CSV::Row.new(['Name', 'Value', 'Date', 'Size'], ['foo', 0])
row # => #<CSV::Row "Name":"foo" "Value":0 "Date":nil "Size":nil>

Each CSV::Row object is either a field row or a header row; by default, a new row is a field row; for the row created above:

Example
row.field_row? # => true
row.header_row? # => false

If the optional argument header_row is given as true, the created row is a header row:

Example
row = CSV::Row.new(['Name', 'Value'], ['foo', 0], header_row = true)
row # => #<CSV::Row "Name":"foo" "Value":0>
row.field_row? # => false
row.header_row? # => true
See also #<< #== also in 3.3 · 3.1 · 3.0