Ruby MCQs with answers Page - 7

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 • 831.35K Points
Coach

Q. Which statement is used to restarts the invocation of the iterator call?

  • (A) break
  • (B) next
  • (C) redo
  • (D) retry

A

Admin • 831.35K Points
Coach

Q. What does the 1..5 indicate?

  • (A) Exclusive range
  • (B) Both inclusive and exclusive range
  • (C) Inclusive range
  • (D) None of the above

A

Admin • 831.35K Points
Coach

Q. Which of the following is Exit Controlled loop?

  • (A) do..while
  • (B) For
  • (C) Until
  • (D) While

A

Admin • 831.35K Points
Coach

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

Code:
for num in 1...5
  puts num
end
  • (A) 1 2 3 4
  • (B) 1 2 3 4 5
  • (C) 0 1 2 3 4
  • (D) 0 1 2 3 4 5

A

Admin • 831.35K Points
Coach

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

Code:
for i in 1...3  
  for j in 1..3
  puts j
  end
end
  • (A) 1 2 1 2
  • (B) 0 1 2 0 1 2
  • (C) 1 2 3 1 2 3
  • (D) 1 2 3 1 2

A

Admin • 831.35K Points
Coach

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

Code:
for num in 1...4

   puts num*num

end
  • (A) 0 1 4 9
  • (B) 1 4 9 16
  • (C) 0 1 2 3
  • (D) 1 2 3

A

Admin • 831.35K Points
Coach

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

Code:
i=1
for i in 6..10
puts i**2
end
  • (A) 36 49 64 81
  • (B) 49 64 81 100
  • (C) 49 64 81
  • (D) 36 49 64 81 100

A

Admin • 831.35K Points
Coach

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

Code:
for i in 1..5 && j in 5..10
puts i+j
end
  • (A) 6 8 10 12 14 16
  • (B) Syntax Error
  • (C) 6 8 10 12 14
  • (D) Type Error

A

Admin • 831.35K Points
Coach

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

Code:
counter = 1
while counter < 5
  puts counter
  counter = counter + 1
end
  • (A) Prints the number from 1 to 4
  • (B) Prints the number from 1 to 5
  • (C) Prints the number from 2 to 5
  • (D) Prints the number from 2 to 4

A

Admin • 831.35K Points
Coach

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

Code:
counter = true
while counter !=false
  puts counter
end
  • (A) TRUE
  • (B) FALSE
  • (C) Syntax Error
  • (D) Infinite Loop

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