Method: CSV.read
- Defined in:
- lib/csv.rb
.read(path, **options) ⇒ Object
:call-seq:
read(source, **options) -> array_of_arrays
read(source, headers: true, **options) -> csv_table
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:
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:
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>
1828 1829 1830 |
# File 'lib/csv.rb', line 1828 def read(path, **) open(path, **) { |csv| csv.read } end |