What is the result of using File.open() with the block syntax in Ruby?
A. The file remains open after the block is executed
B. The file is opened in write mode
C. The file is opened in read mode
D. The file is automatically closed at the end of the block
Answer: Option D
What does File.open() return in Ruby when the file is successfully opened?
A. Integer representing file descriptor
B. Array of file contents
C. Boolean value
D. File object
How do you open a file in Ruby in write mode, creating it if it does not exist?
A. File.create("filename.txt", "w")
B. File.write("filename.txt", "w")
C. File.open("filename.txt", "w")
D. File.new("filename.txt", "w")
Which method in Ruby is used to read a line from a file?
A. read
B. readline
C. getline
D. None of the above
What is the purpose of the File.readlines() method in Ruby?
A. To delete all lines from a file
B. To write all lines of a file from an array
C. To read all lines of a file into an array
D. To read a specific line from a file

Join The Discussion