Bird
0
0

Which Ruby method from the CSV library is used to read all rows from a CSV file into an array?

easy📝 Conceptual Q2 of 15
Ruby - File IO
Which Ruby method from the CSV library is used to read all rows from a CSV file into an array?
ACSV.open
BCSV.read
CCSV.generate
DCSV.write
Step-by-Step Solution
Solution:
  1. Step 1: Recall CSV methods for reading

    CSV.read reads the entire CSV file and returns an array of rows.
  2. Step 2: Compare other methods

    CSV.open is for opening files with a block, CSV.generate creates CSV data as a string, CSV.write writes data to a file.
  3. Final Answer:

    CSV.read -> Option B
  4. Quick Check:

    Method to read all rows = CSV.read [OK]
Quick Trick: Use CSV.read to get all rows as an array [OK]
Common Mistakes:
  • Using CSV.open to read all rows
  • Confusing CSV.generate with reading

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes