Method: CSV::Table#<<
- Defined in:
- lib/csv/table.rb
#<<(row_or_array) ⇒ Object
:call-seq:
table << row_or_array -> self
If row_or_array is a CSV::Row object, it is appended to the table:
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:
table << ['bam', 4]
table[4] # => #<CSV::Row "Name":"bam" "Value":4>
762 763 764 765 766 767 768 769 770 |
# File '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 |