Ruby - File IOWhat does the 'r' mode do when opening a file in Ruby?AOpens the file for reading only, without changing its content.BOpens the file for writing and erases existing content.COpens the file for appending new content at the end.DCreates a new file if it doesn't exist and writes to it.Check Answer
Step-by-Step SolutionSolution:Step 1: Understand the purpose of 'r' modeThe 'r' mode is used to open a file only for reading, so the file content is not changed.Step 2: Compare with other modes'w' mode writes and erases content, 'a' appends, but 'r' only reads.Final Answer:Opens the file for reading only, without changing its content. -> Option AQuick Check:'r' = read only [OK]Quick Trick: Remember 'r' stands for read only, no changes made [OK]Common Mistakes:Confusing 'r' with 'w' and thinking it erases contentAssuming 'r' can write to the fileMixing 'r' with 'a' mode functionality
Master "File IO" in Ruby9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Ruby Quizzes Blocks, Procs, and Lambdas - Method objects with method() - Quiz 4medium Blocks, Procs, and Lambdas - Closures and variable binding - Quiz 14medium Blocks, Procs, and Lambdas - Block given? check - Quiz 14medium Class Methods and Variables - Open classes (reopening classes) - Quiz 15hard Classes and Objects - Initialize method as constructor - Quiz 4medium Enumerable and Collection Processing - Group_by for categorization - Quiz 13medium Error Handling - Ensure for cleanup - Quiz 3easy Error Handling - Why error handling uses rescue - Quiz 1easy Error Handling - Rescue modifier (inline form) - Quiz 3easy File IO - Why file handling matters - Quiz 13medium