Ruby File Handling MCQ

This section focuses on "File Handling" MCQs in Ruby. These Multiple Choice Questions (mcq) should be practiced to improve the Ruby skills required for various interviews (campus interviews, walk-in interviews, company interviews), placements, entrance exams and other competitive examinations.

1. Which of the following is not correct method class IO provides?

A. readline
B. gets
C. puts
D. Writeline

View Answer


2. What will be output for the following code?

val1 = ""This is variable one""
puts ""val1""

A. This is variable one
B. VAL1
C. This is variable one val1
D. val1

View Answer


3. Which statement can be used to take any input from the user from standard screen?

A. gets
B. puts
C. read
D. write

View Answer


4. What will be output for the following code?

str = ""Hello Ruby!""
putc str

A. Hello Ruby!
B. H
C. R
D. Hello

View Answer


5. What is the syntax to close file in ruby?

A. File.close()
B. close.File
C. File.close
D. close.File()

View Answer


6. What is the syntax to open file in ruby?

A. File.open("filename", "mode")
B. File.open("filename")
C. File.open()
D. All of the above

View Answer


7. Which method is used to write content in the file ?

A. systemwrite
B. sysputs
C. syswrite
D. systemputs

View Answer


8. Which of the following is correct difference between foreach and readlines?

A. The method readline does not return an array.
B. The method foreach does not return an array.
C. readline is associated with a block
D. Both A and C

View Answer


9. Which of the method is used to returns the contents of the file line by line?

A. IO.read
B. IO.foreach
C. IO.syswrite
D. IO.readlines

View Answer


10. Which method is used to change the mode or permissions/access list of a file?

A. mode
B. chmod
C. access
D. permissions

View Answer





Discussion


* You must be logged in to add comment.