Ruby MCQs with answers Page - 10

Here, you will find a collection of MCQ questions on Ruby. Go through these questions to enhance your preparation for upcoming examinations and interviews.

To check the correct answer, simply click the View Answer button provided for each question.

Have your own questions to contribute? Click the button below to share your MCQs with others!

+ Add Question

A

Admin • 828.03K Points
Coach

Q. What is the output of the given ruby code?

Code:
a=[[a,b]]
b=[[e,a]]
print a + b
  • (A) [["a", "b"], ["e", "a"]].
  • (B) [["2a", "b"], ["e"]].
  • (C) TRUE
  • (D) FALSE

A

Admin • 828.03K Points
Coach

Q. What will be the output of the given ruby code?

Code:
a=[1,2,3,4,5]
b=[1,2,4,6,8]
if a[3]==b[2]
    print Equal
end
  • (A) TRUE
  • (B) FALSE
  • (C) Equal
  • (D) error

A

Admin • 828.03K Points
Coach

Q. What is the output of the given ruby code?

Code:
array1 = [[1,2,3,4],[0,0,0,0]]
array2 = [[1,2,3,4],[0,0,0,0]]
print array1-array2
  • (A) [[1, 2, 3, 4], [0, 0, 0, 0]]
  • (B) [[1, 2, 3, 4], [0, 0, 0, 0], [1, 2, 3, 4], [0, 0, 0, 0]]
  • (C) []
  • (D) Nil

A

Admin • 828.03K Points
Coach

Q. What is the output of the given code?

Code:
array1 = [[1,2,3,4,5],[0,0,0,0]]
print !array1
  • (A) Error
  • (B) [[1, 2, 3, 4, 5], [0, 0, 0, 0]].
  • (C) TRUE
  • (D) FALSE

A

Admin • 828.03K Points
Coach

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

  • (A) readline
  • (B) gets
  • (C) puts
  • (D) Writeline

A

Admin • 828.03K Points
Coach

Q. What will be output for the following code?

Code:
val1 = ""This is variable one""
puts ""val1""
  • (A) This is variable one
  • (B) VAL1
  • (C) This is variable one val1
  • (D) val1

A

Admin • 828.03K Points
Coach

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

  • (A) gets
  • (B) puts
  • (C) read
  • (D) write

A

Admin • 828.03K Points
Coach

Q. What will be output for the following code?

Code:
str = ""Hello Ruby!""
putc str
  • (A) Hello Ruby!
  • (B) H
  • (C) R
  • (D) Hello

A

Admin • 828.03K Points
Coach

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

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

A

Admin • 828.03K Points
Coach

Q. 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

Add MCQ in this Category

If you want to share an MCQ question in this category, it's a great idea! It will be helpful for many other students using this website.

Share Your MCQ