What does the truncate method do in Ruby file I/O?
A. Truncates the file to the end of the file
B. Truncates the file to the beginning of the file
C. Truncates the file to the current position of the file pointer
D. Truncates the file to a specified size
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