Ruby MCQs with answers Page - 9

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. Each element in an array is associated with _______.

  • (A) Numbers
  • (B) Index
  • (C) Integer
  • (D) None of the above

A

Admin • 828.03K Points
Coach

Q. Array indexing in ruby starts at_________.

  • (A) -1
  • (B) 1
  • (C) 0
  • (D) Random number

A

Admin • 828.03K Points
Coach

Q. In Ruby, Array index -1 represent ______.

  • (A) First Element
  • (B) Last element
  • (C) Middle element
  • (D) Reverse the array

A

Admin • 828.03K Points
Coach

Q. Which of the following is correct syntax to create an array in ruby?

  • (A) names = Array.new
  • (B) names = Array.new(20)
  • (C) Both A and B
  • (D) None of the above

A

Admin • 828.03K Points
Coach

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

Code:
digits = Array(0...9)
puts #{digits}
  • (A) [0, 1, 2, 3, 4, 5, 6, 7, 8]
  • (B) [0, 1, 2, 3, 4, 5, 6, 7, 8]
  • (C) [0, 1, 2, 3, 4, 5, 6, 7, 8,9]
  • (D) [1, 2, 3, 4, 5, 6, 7, 8]

A

Admin • 828.03K Points
Coach

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

Code:
digits = Array(0..9)
num = digits.at(6)
puts #{num}
  • (A) 5
  • (B) 6
  • (C) 7
  • (D) 8

A

Admin • 828.03K Points
Coach

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

  • (A) ABC
  • (B) abc
  • (C) BCD
  • (D) bcd

A

Admin • 828.03K Points
Coach

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

Code:
arr = [1, 2, 3, 4]
print arr
  • (A) [1, 2, 3, 4]
  • (B) 1234
  • (C) error
  • (D) Infinite Loop

A

Admin • 828.03K Points
Coach

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

Code:
string_array = [a,e,i,o,u]
print string_array
  • (A) Error
  • (B) ["a","e","i","o","u"]
  • (C) aeiou
  • (D) Infinite Loop

A

Admin • 828.03K Points
Coach

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

Code:
arr = [[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]
print arr
  • (A) [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]].
  • (B) [0, 0, 0, 0][0, 0, 0, 0]
  • (C) [0, 0, 0, 0]
  • (D) error

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