Bird
0
0

What does the 'r' mode do when opening a file in Ruby?

easy📝 Conceptual Q11 of 15
Ruby - File IO
What 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.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the purpose of 'r' mode

    The 'r' mode is used to open a file only for reading, so the file content is not changed.
  2. Step 2: Compare with other modes

    'w' mode writes and erases content, 'a' appends, but 'r' only reads.
  3. Final Answer:

    Opens the file for reading only, without changing its content. -> Option A
  4. Quick 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 content
  • Assuming 'r' can write to the file
  • Mixing 'r' with 'a' mode functionality

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes