Bird
0
0

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

easy📝 Syntax Q12 of 15
Ruby - File IO
Which of the following is the correct syntax to write the string "Hello" to a file named "greet.txt" using File.write in Ruby?
AFile.write("greet.txt") { "Hello" }
BFile.write("Hello", "greet.txt")
CFile.write("greet.txt", "Hello")
DFile.write("greet.txt" => "Hello")
Step-by-Step Solution
Solution:
  1. Step 1: Identify File.write parameters

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

    File.write("greet.txt", "Hello") correctly uses File.write("greet.txt", "Hello").
  3. Final Answer:

    File.write("greet.txt", "Hello") -> Option C
  4. Quick Check:

    File.write(filename, content) = C [OK]
Quick Trick: Filename first, content second in File.write [OK]
Common Mistakes:
  • Swapping filename and content arguments
  • Using block syntax incorrectly
  • Passing a hash instead of arguments

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes