Bird
0
0

What is wrong with this Ruby code snippet?

medium📝 Debug Q6 of 15
Ruby - File IO
What is wrong with this Ruby code snippet?
content = File.read
puts content
AFile.read returns nil without a file
BFile.read requires a filename argument
CFile.read cannot be used with puts
DNo error, code works fine
Step-by-Step Solution
Solution:
  1. Step 1: Check File.read usage

    File.read must be called with a filename string argument.
  2. Step 2: Identify error cause

    Calling File.read without arguments causes an ArgumentError.
  3. Final Answer:

    File.read requires a filename argument -> Option B
  4. Quick Check:

    File.read needs filename argument = C [OK]
Quick Trick: Always provide filename string to File.read [OK]
Common Mistakes:
  • Calling File.read without arguments
  • Assuming File.read returns nil if no file given
  • Thinking puts causes error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes