End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
class method
CSV.read
read(source, **options) → array_of_arrays
read(source, headers: true, **options) → csv_table
lib/csv.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.0.5/lib/csv.rb, line 1656
def read(path, **options)
open(path, **options) { |csv| csv.read }
end
Opens the given source with the given options (see CSV.open), reads the source (see CSV#read), and returns the result, which will be either an Array of Arrays or a CSV::Table.
Without headers:
Example
string = "foo,0\nbar,1\nbaz,2\n" path = 't.csv' File.write(path, string) CSV.read(path) # => [["foo", "0"], ["bar", "1"], ["baz", "2"]]
With headers:
Example
string = "Name,Value\nfoo,0\nbar,1\nbaz,2\n" path = 't.csv' File.write(path, string) CSV.read(path, headers: true) # => #<CSV::Table mode:col_or_row row_count:4>