Method: CSV::Row#<<
- Defined in:
- lib/csv.rb
#<<(arg) ⇒ Object
:call-seq:
<<( field )
<<( header_and_field_array )
<<( header_and_field_hash )
If a two-element Array is provided, it is assumed to be a header and field and the pair is appended. A Hash works the same way with the key being the header and the value being the field. Anything else is assumed to be a lone field which is appended with a nil header.
This method returns the row for chaining.
382 383 384 385 386 387 388 389 390 391 392 |
# File 'lib/csv.rb', line 382 def <<(arg) if arg.is_a?(Array) and arg.size == 2 # appending a header and name @row << arg elsif arg.is_a?(Hash) # append header and name pairs arg.each { |pair| @row << pair } else # append field value @row << [nil, arg] end self # for chaining end |