Method: CSV::Table#by_row
- Defined in:
- lib/csv/table.rb
#by_row ⇒ Object
:call-seq:
table.by_row -> table_dup
Returns a duplicate of self, in row mode (see Row Mode):
source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
table = CSV.parse(source, headers: true)
table.mode # => :col_or_row
dup_table = table.by_row
dup_table.mode # => :row
dup_table.equal?(table) # => false # It's a dup
This may be used to chain method calls without changing the mode (but also will affect performance and memory usage):
dup_table.by_row[1]
Also note that changes to the duplicate table will not affect the original.
318 319 320 |
# File 'lib/csv/table.rb', line 318 def by_row self.class.new(@table.dup).by_row! end |