Skip to content

End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

CSV::Table#by_col_or_row

table.by_col_or_row → table_dup

Returns a duplicate of self, in mixed mode (see Mixed Mode):

Example
source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
table = CSV.parse(source, headers: true).by_col!
table.mode # => :col
dup_table = table.by_col_or_row
dup_table.mode # => :col_or_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):

Example
dup_table.by_col_or_row['Name']

Also note that changes to the duplicate table will not affect the original.

See also #by_col_or_row! #by_col! #by_col #by_row also in 3.3 · 3.1 · 3.0