Which method in Ruby is used to set the position of the file pointer?
A. seek()
B. position()
C. set_pointer()
D. pointer_position()
Answer: Option A
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