Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
CSV::Table#by_col
table.by_col → table_dup
lib/csv/table.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.3.0/lib/csv/table.rb, line 242
def by_col
self.class.new(@table.dup).by_col!
end
Returns a duplicate of self, in column mode (see Column Mode):
Example
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_col dup_table.mode # => :col 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['Name']
Also note that changes to the duplicate table will not affect the original.