End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
class method
CSV.table
CSV.table(source, **options)
lib/csv.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.1.3/lib/csv.rb, line 1855
def table(path, **options)
default_options = {
headers: true,
converters: :numeric,
header_converters: :symbol,
}
options = default_options.merge(options)
read(path, **options)
end
Calls CSV.read with source, options, and certain default options:
-
headers:true -
converters::numeric -
header_converters::symbol
Returns a CSV::Table object.
Example:
Example
string = "Name,Value\nfoo,0\nbar,1\nbaz,2\n" path = 't.csv' File.write(path, string) CSV.table(path) # => #<CSV::Table mode:col_or_row row_count:4>