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#<<
table << row_or_array → self
lib/csv/table.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.1.3/lib/csv/table.rb, line 762
def <<(row_or_array)
if row_or_array.is_a? Array # append Array
@table << Row.new(headers, row_or_array)
else # append Row
@table << row_or_array
end
self # for chaining
end
If row_or_array is a CSV::Row object, it is appended to the table:
Example
source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n" table = CSV.parse(source, headers: true) table << CSV::Row.new(table.headers, ['bat', 3]) table[3] # => #<CSV::Row "Name":"bat" "Value":3>
If row_or_array is an Array, it is used to create a new CSV::Row object which is then appended to the table:
Example
table << ['bam', 4] table[4] # => #<CSV::Row "Name":"bam" "Value":4>