File Input Output In Ruby - Study Mode

[#1] What does File.open() return in Ruby when the file is successfully opened?
Correct Answer

(D) File object

[#2] How do you open a file in Ruby in write mode, creating it if it does not exist?
Correct Answer

(C) File.open("filename.txt", "w")

[#3] Which method in Ruby is used to read a line from a file?
Correct Answer

(B) readline

[#4] What is the purpose of the File.readlines() method in Ruby?
Correct Answer

(C) To read all lines of a file into an array

[#5] How do you close a file in Ruby after performing file operations?
Correct Answer

(D) file.close()