Bird
0
0

Which of the following is the correct syntax to write the string "Ruby Rocks" to a file named "output.txt" using File.write?

easy📝 Syntax Q3 of 15
Ruby - File IO
Which of the following is the correct syntax to write the string "Ruby Rocks" to a file named "output.txt" using File.write?
AFile.write("output.txt") { "Ruby Rocks" }
BFile.write("Ruby Rocks", "output.txt")
CFile.write("output.txt", "Ruby Rocks")
DFile.write { "output.txt", "Ruby Rocks" }
Step-by-Step Solution
Solution:
  1. Step 1: Recall File.write parameter order

    The first argument is the filename, second is the string to write.
  2. Step 2: Match correct syntax

    File.write("output.txt", "Ruby Rocks") matches this order and syntax correctly.
  3. Final Answer:

    File.write("output.txt", "Ruby Rocks") -> Option C
  4. Quick Check:

    Syntax = File.write(filename, content) [OK]
Quick Trick: File.write(filename, content) is correct syntax [OK]
Common Mistakes:
  • Swapping filename and content arguments
  • Using block syntax incorrectly
  • Passing arguments inside a block

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes