Ruby - File IOWhat 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.Check Answer
Step-by-Step SolutionSolution:Step 1: Understand CSV.foreach purposeThe method CSV.foreach is designed to read CSV files line by line.Step 2: Identify the output formatEach line is yielded as an array of strings representing the cells in that row.Final Answer:Reads a CSV file line by line, yielding each row as an array. -> Option AQuick Check:CSV.foreach reads lines as arrays [OK]Quick Trick: Remember: foreach reads rows, open writes rows [OK]Common Mistakes:Confusing reading with writing methodsThinking it returns a hash instead of an arrayAssuming it deletes files
Master "File IO" in Ruby9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Ruby Quizzes Blocks, Procs, and Lambdas - Proc vs lambda differences (arity, return) - Quiz 12easy Blocks, Procs, and Lambdas - Method objects with method() - Quiz 15hard Class Methods and Variables - Class variables (@@) and their dangers - Quiz 5medium Enumerable and Collection Processing - Reject for inverse filtering - Quiz 5medium Enumerable and Collection Processing - Reduce/inject for accumulation - Quiz 10hard File IO - Dir operations for directories - Quiz 4medium Modules and Mixins - Custom modules as mixins - Quiz 6medium Modules and Mixins - Extend for class methods - Quiz 1easy Modules and Mixins - Module declaration syntax - Quiz 7medium Modules and Mixins - Namespacing with modules - Quiz 7medium