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#push

table.push(*rows_or_arrays) → self

A shortcut for appending multiple rows. Equivalent to:

Example
rows.each {|row| self << row }

Each argument may be either a CSV::Row object or an Array:

Example
source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
table = CSV.parse(source, headers: true)
rows = [
  CSV::Row.new(table.headers, ['bat', 3]),
  ['bam', 4]
]
table.push(*rows)
table[3..4] # => [#<CSV::Row "Name":"bat" "Value":3>, #<CSV::Row "Name":"bam" "Value":4>]
See also #inspect #to_a #headers #to_csv also in 3.3 · 3.2 · 3.0