Practice high-yield Programming & Software Development MCQs on File Input Output In Ruby with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.
Questions
33
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
40 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
33
Verified Practice Questions
Interactive test mode with detailed academic worked solutions
Live Progress|0/33 answered
✓0 correct
✗0 wrong
0% score
🎉 Set complete! All 33 questions answered.
Question 1 of 33
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does File.open() return in Ruby when the file is successfully opened?
Correct Answer: Option D — File object
Detailed Academic Explanation:
File object is the correct answer to “What does File.open() return in Ruby when the file is successfully opened”. This question is standard in competitive examination syllabi for File Input Output In Ruby.
💡Key Conceptual Anchor:File Input Output In Ruby
Question 2 of 33
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you open a file in Ruby in write mode, creating it if it does not exist?
Correct Answer: Option C — File.open("filename.txt", "w")
Detailed Academic Explanation:
File.open("filename.txt", "w") is the correct answer to “How do you open a file in Ruby in write mode, creating it if it does not exist”. This question is standard in competitive examination syllabi for File Input Output In Ruby.
💡Key Conceptual Anchor:File Input Output In Ruby
Question 3 of 33
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which method in Ruby is used to read a line from a file?
Correct Answer: Option B — readline
Detailed Academic Explanation:
readline is the correct answer to “Which method in Ruby is used to read a line from a file”. This question is standard in competitive examination syllabi for File Input Output In Ruby.
💡Key Conceptual Anchor:File Input Output In Ruby
Question 4 of 33
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the File.readlines() method in Ruby?
Correct Answer: Option C — To read all lines of a file into an array
Detailed Academic Explanation:
To read all lines of a file into an array is the correct answer to “What is the purpose of the File.readlines() method in Ruby”. This question is standard in competitive examination syllabi for File Input Output In Ruby.
💡Key Conceptual Anchor:File Input Output In Ruby
Question 5 of 33
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you close a file in Ruby after performing file operations?
Correct Answer: Option D — file.close()
Detailed Academic Explanation:
file.close() is the correct answer to “How do you close a file in Ruby after performing file operations”. This question is standard in competitive examination syllabi for File Input Output In Ruby.
💡Key Conceptual Anchor:File Input Output In Ruby
Question 6 of 33
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which method in Ruby is used to write data to a file?
Correct Answer: Option A — write()
Detailed Academic Explanation:
write() is the correct answer to “Which method in Ruby is used to write data to a file”. This question is standard in competitive examination syllabi for File Input Output In Ruby.
💡Key Conceptual Anchor:File Input Output In Ruby
Question 7 of 33
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the 'a+' file mode in Ruby signify?
Correct Answer: Option D — Opens a file for reading and appending, creating it if it does not exist
Detailed Academic Explanation:
Opens a file for reading and appending, creating it if it does not exist is the correct answer to “What does the 'a+' file mode in Ruby signify”. This question is standard in competitive examination syllabi for File Input Output In Ruby.
💡Key Conceptual Anchor:File Input Output In Ruby
Question 8 of 33
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which method in Ruby is used to check if the end of a file has been reached?
Correct Answer: Option C — eof()
Detailed Academic Explanation:
eof() is the correct answer to “Which method in Ruby is used to check if the end of a file has been reached”. This question is standard in competitive examination syllabi for File Input Output In Ruby.
💡Key Conceptual Anchor:File Input Output In Ruby
Question 9 of 33
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the File.exist? method in Ruby return if the specified file exists?
Correct Answer: Option B — TRUE
Detailed Academic Explanation:
TRUE is the correct answer to “What does the File.exist? method in Ruby return if the specified file exists”. This question is standard in competitive examination syllabi for File Input Output In Ruby.
💡Key Conceptual Anchor:File Input Output In Ruby
Question 10 of 33
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the 'r+' file mode in Ruby signify?
Correct Answer: Option C — Opens a file for reading and writing, creating it if it does not exist
Detailed Academic Explanation:
Opens a file for reading and writing, creating it if it does not exist is the correct answer to “What does the 'r+' file mode in Ruby signify”. This question is standard in competitive examination syllabi for File Input Output In Ruby.
💡Key Conceptual Anchor:File Input Output In Ruby
Question 11 of 33
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the File.exist? method in Ruby?
Correct Answer: Option D — To check if the specified file exists
Detailed Academic Explanation:
To check if the specified file exists is the correct answer to “What is the purpose of the File.exist? method in Ruby”. This question is standard in competitive examination syllabi for File Input Output In Ruby.
💡Key Conceptual Anchor:File Input Output In Ruby
Question 12 of 33
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which method in Ruby is used to set the position of the file pointer?
Correct Answer: Option A — seek()
Detailed Academic Explanation:
seek() is the correct answer to “Which method in Ruby is used to set the position of the file pointer”. This question is standard in competitive examination syllabi for File Input Output In Ruby.
💡Key Conceptual Anchor:File Input Output In Ruby
Question 13 of 33
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the File.rename() method in Ruby do?
Correct Answer: Option D — Renames a file
Detailed Academic Explanation:
Renames a file is the correct answer to “What does the File.rename() method in Ruby do”. This question is standard in competitive examination syllabi for File Input Output In Ruby.
💡Key Conceptual Anchor:File Input Output In Ruby
Question 14 of 33
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you read the entire contents of a file into a string in Ruby?
Correct Answer: Option C — file.read()
Detailed Academic Explanation:
file.read() is the correct answer to “How do you read the entire contents of a file into a string in Ruby”. This question is standard in competitive examination syllabi for File Input Output In Ruby.
💡Key Conceptual Anchor:File Input Output In Ruby
Question 15 of 33
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which method in Ruby is used to delete a file?
Correct Answer: Option B — File.delete()
Detailed Academic Explanation:
File.delete() is the correct answer to “Which method in Ruby is used to delete a file”. This question is standard in competitive examination syllabi for File Input Output In Ruby.
💡Key Conceptual Anchor:File Input Output In Ruby
Question 16 of 33
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the File.size method in Ruby?
Correct Answer: Option C — To determine the size of a file in bytes
Detailed Academic Explanation:
To determine the size of a file in bytes is the correct answer to “What is the purpose of the File.size method in Ruby”. This question is standard in competitive examination syllabi for File Input Output In Ruby.
💡Key Conceptual Anchor:File Input Output In Ruby
Question 17 of 33
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the result of using File.open() with the block syntax in Ruby?
Correct Answer: Option D — The file is automatically closed at the end of the block
Detailed Academic Explanation:
The file is automatically closed at the end of the block is the correct answer to “What is the result of using File.open() with the block syntax in Ruby”. This question is standard in competitive examination syllabi for File Input Output In Ruby.
💡Key Conceptual Anchor:File Input Output In Ruby
Question 18 of 33
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the 'w' file mode in Ruby signify?
Correct Answer: Option A — Opens a file for writing, truncating it if it exists
Detailed Academic Explanation:
Opens a file for writing, truncating it if it exists is the correct answer to “What does the 'w' file mode in Ruby signify”. This question is standard in competitive examination syllabi for File Input Output In Ruby.
💡Key Conceptual Anchor:File Input Output In Ruby
Question 19 of 33
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you check if a file in Ruby is readable?
Correct Answer: Option D — File.readable?("filename.txt")
Detailed Academic Explanation:
File.readable?("filename.txt") is the correct answer to “How do you check if a file in Ruby is readable”. This question is standard in competitive examination syllabi for File Input Output In Ruby.
💡Key Conceptual Anchor:File Input Output In Ruby
Question 20 of 33
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What method is used to check if a file is writable in Ruby?
Correct Answer: Option C — File.writable?("filename")
Detailed Academic Explanation:
File.writable?("filename") is the correct answer to “What method is used to check if a file is writable in Ruby”. This question is standard in competitive examination syllabi for File Input Output In Ruby.
💡Key Conceptual Anchor:File Input Output In Ruby
Question 21 of 33
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you check the size of a file in Ruby?
Correct Answer: Option B — Using File.size method
Detailed Academic Explanation:
Using File.size method is the correct answer to “How do you check the size of a file in Ruby”. This question is standard in competitive examination syllabi for File Input Output In Ruby.
💡Key Conceptual Anchor:File Input Output In Ruby
Question 22 of 33
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which method is used to delete a file in Ruby?
Correct Answer: Option C — File.delete("filename")
Detailed Academic Explanation:
File.delete("filename") is the correct answer to “Which method is used to delete a file in Ruby”. This question is standard in competitive examination syllabi for File Input Output In Ruby.
💡Key Conceptual Anchor:File Input Output In Ruby
Question 23 of 33
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the binmode method do in Ruby file I/O?
Correct Answer: Option D — Sets the file mode to binary mode
Detailed Academic Explanation:
Sets the file mode to binary mode is the correct answer to “What does the binmode method do in Ruby file I/O”. This question is standard in competitive examination syllabi for File Input Output In Ruby.
💡Key Conceptual Anchor:File Input Output In Ruby
Question 24 of 33
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How can you check if a file is readable in Ruby?
Correct Answer: Option A — Using File.readable? method
Detailed Academic Explanation:
Using File.readable? method is the correct answer to “How can you check if a file is readable in Ruby”. This question is standard in competitive examination syllabi for File Input Output In Ruby.
💡Key Conceptual Anchor:File Input Output In Ruby
Question 25 of 33
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the truncate method do in Ruby file I/O?
Correct Answer: Option D — Truncates the file to a specified size
Detailed Academic Explanation:
Truncates the file to a specified size is the correct answer to “What does the truncate method do in Ruby file I/O”. This question is standard in competitive examination syllabi for File Input Output In Ruby.
💡Key Conceptual Anchor:File Input Output In Ruby
Question 26 of 33
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which method is used to check if a file is executable in Ruby?
Correct Answer: Option C — File.executable?("filename")
Detailed Academic Explanation:
File.executable?("filename") is the correct answer to “Which method is used to check if a file is executable in Ruby”. This question is standard in competitive examination syllabi for File Input Output In Ruby.
💡Key Conceptual Anchor:File Input Output In Ruby
Question 27 of 33
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How can you get the absolute path of a file in Ruby?
Correct Answer: Option B — Using File.expand_path method
Detailed Academic Explanation:
Using File.expand_path method is the correct answer to “How can you get the absolute path of a file in Ruby”. This question is standard in competitive examination syllabi for File Input Output In Ruby.
💡Key Conceptual Anchor:File Input Output In Ruby
Question 28 of 33
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the fcntl method do in Ruby file I/O?
Correct Answer: Option C — Manipulates file descriptor
Detailed Academic Explanation:
Manipulates file descriptor is the correct answer to “What does the fcntl method do in Ruby file I/O”. This question is standard in competitive examination syllabi for File Input Output In Ruby.
💡Key Conceptual Anchor:File Input Output In Ruby
Question 29 of 33
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you create a new directory in Ruby?
Correct Answer: Option D — Using Dir.mkdir method
Detailed Academic Explanation:
Using Dir.mkdir method is the correct answer to “How do you create a new directory in Ruby”. This question is standard in competitive examination syllabi for File Input Output In Ruby.
💡Key Conceptual Anchor:File Input Output In Ruby
Question 30 of 33
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the chown method in Ruby file I/O?
Correct Answer: Option C — Changes the file owner and group
Detailed Academic Explanation:
Changes the file owner and group is the correct answer to “What is the purpose of the chown method in Ruby file I/O”. This question is standard in competitive examination syllabi for File Input Output In Ruby.
💡Key Conceptual Anchor:File Input Output In Ruby
Question 31 of 33
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which method is used to check if a file is hidden in Ruby?
Correct Answer: Option D — File.hidden?("filename")
Detailed Academic Explanation:
File.hidden?("filename") is the correct answer to “Which method is used to check if a file is hidden in Ruby”. This question is standard in competitive examination syllabi for File Input Output In Ruby.
💡Key Conceptual Anchor:File Input Output In Ruby
Question 32 of 33
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the ctime method return in Ruby file I/O?
Correct Answer: Option A — The last status change time of the file
Detailed Academic Explanation:
The last status change time of the file is the correct answer to “What does the ctime method return in Ruby file I/O”. This question is standard in competitive examination syllabi for File Input Output In Ruby.
💡Key Conceptual Anchor:File Input Output In Ruby
Question 33 of 33
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which method is used to retrieve file attributes in Ruby?
Correct Answer: Option D — File.stat("filename")
Detailed Academic Explanation:
File.stat("filename") is the correct answer to “Which method is used to retrieve file attributes in Ruby”. This question is standard in competitive examination syllabi for File Input Output In Ruby.
💡Key Conceptual Anchor:File Input Output In Ruby
✓Link copied to clipboard
Continue Your Practice
Advance Html — Part 1
Master the next curriculum module with 40 exam-standard MCQs.
💡Examiner's Advisory for Programming & Software Development
In competitive commission exams (FPSC, PPSC, KPPSC, SPSC, CSS, PMS), questions are frequently phrased with distractor options designed to catch rote learners. Whenever you answer an MCQ, read the Detailed Academic Explanation and Conceptual Anchor to understand why the remaining options are incorrect.