Recall & Review
beginner
What is the purpose of the CSV library in Ruby?
The CSV library helps read from and write to CSV (Comma-Separated Values) files easily, making it simple to handle tabular data.
Click to reveal answer
beginner
How do you require the CSV library in a Ruby script?
Use
require 'csv' at the top of your Ruby file to load the CSV library.Click to reveal answer
beginner
How do you read a CSV file line by line in Ruby?
Use
CSV.foreach('filename.csv') do |row| ... end. Each row is an array of values from that line.Click to reveal answer
intermediate
How do you write an array of arrays to a CSV file in Ruby?
Use
CSV.open('filename.csv', 'w') do |csv| data.each { |row| csv << row } end where data is an array of arrays.Click to reveal answer
intermediate
What does
CSV.parse do?CSV.parse reads CSV data from a string instead of a file, returning an array of rows.Click to reveal answer
Which Ruby command loads the CSV library?
✗ Incorrect
In Ruby,
require 'csv' loads the CSV library.What does
CSV.foreach('file.csv') do |row| ... end do?✗ Incorrect
It reads the CSV file line by line and gives each row as an array to the block.
How do you write data to a CSV file in Ruby?
✗ Incorrect
Use
CSV.open with write mode and add rows with <<.What type of object is each row when reading CSV with
CSV.foreach?✗ Incorrect
Each row is an array of values from the CSV line.
Which method reads CSV data from a string instead of a file?
✗ Incorrect
CSV.parse reads CSV data from a string.Explain how to read a CSV file line by line in Ruby using the CSV library.
Think about how to open and process each line easily.
You got /4 concepts.
Describe the steps to write multiple rows of data to a CSV file in Ruby.
Consider how to open a file for writing and add rows one by one.
You got /4 concepts.