Bird
0
0

What does the Ruby CSV method CSV.foreach do?

easy📝 Conceptual Q11 of 15
Ruby - File IO
What does the Ruby CSV method CSV.foreach do?
AReads a CSV file line by line, yielding each row as an array.
BWrites data to a CSV file line by line.
CConverts a CSV file into a hash with headers as keys.
DDeletes a CSV file from the system.
Step-by-Step Solution
Solution:
  1. Step 1: Understand CSV.foreach purpose

    The method CSV.foreach is designed to read CSV files line by line.
  2. Step 2: Identify the output format

    Each line is yielded as an array of strings representing the cells in that row.
  3. Final Answer:

    Reads a CSV file line by line, yielding each row as an array. -> Option A
  4. Quick Check:

    CSV.foreach reads lines as arrays [OK]
Quick Trick: Remember: foreach reads rows, open writes rows [OK]
Common Mistakes:
  • Confusing reading with writing methods
  • Thinking it returns a hash instead of an array
  • Assuming it deletes files

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes