Skip to content

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

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>
See also .new #== #[] also in 3.3 · 3.2 · 3.0