CSV
Comma-separated data files are often used to transfer tabular information, especially for importing and exporting spreadsheet and database information. Ruby’s current CSV library is based on James Edward Gray II’s FasterCSV gem. The CSV object has possibly the best official documentation in the entire Ruby library, and it goes beyond what’s discussed here.
Ruby’s CSV library deals with arrays (corresponding to the rows in the CSV file) and strings (corresponding to the elements in a row). If an element in a row is missing, it’ll be represented as nil in Ruby.
The generic CSV parsing method is CSV.parse(string_or_io, headers: nil, **options) [{|row|}] and takes an optional block. The main argument is either a string or an IO object and ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access