End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
class method
CSV::Row.new
new(headers, fields, header_row = false)
lib/csv/row.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.0.5/lib/csv/row.rb, line 30
def initialize(headers, fields, header_row = false)
@header_row = header_row
headers.each { |h| h.freeze if h.is_a? String }
# handle extra headers or fields
@row = if headers.size >= fields.size
headers.zip(fields)
else
fields.zip(headers).each(&:reverse!)
end
end
Constructs a new CSV::Row from headers and fields, which are expected to be Arrays. If one Array is shorter than the other, it will be padded with nil objects.
The optional header_row parameter can be set to true to indicate, via CSV::Row.header_row?() and CSV::Row.field_row?(), that this is a header row. Otherwise, the row assumes to be a field row.
A CSV::Row object supports the following Array methods through delegation:
-
empty?()
-
length()
-
size()