Ruby MCQs with answers Page - 105

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. Which keyword is used to raise an exception in Ruby?

  • (A) throw
  • (B) raise
  • (C) catch
  • (D) error

A

Admin • 828.03K Points
Coach

Q. Which keyword is used to exit a loop in Ruby?

  • (A) break
  • (B) stop
  • (C) exit
  • (D) end

A

Admin • 828.03K Points
Coach

Q. Which method converts a string to uppercase in Ruby?

  • (A) upcase
  • (B) uppercase
  • (C) toUpperCase
  • (D) capitalize

A

Admin • 828.03K Points
Coach

Q. How do you define a constant in Ruby?

  • (A) Starting with uppercase letter
  • (B) Starting with lowercase letter
  • (C) Starting with underscore
  • (D) Starting with $ sign

A

Admin • 828.03K Points
Coach

Q. What is the output of 'nil.nil?' in Ruby?

  • (A) true
  • (B) false
  • (C) nil
  • (D) error

A

Admin • 828.03K Points
Coach

Q. Which method is used to check if an array includes a specific element?

  • (A) include?
  • (B) has?
  • (C) contains?
  • (D) exists?

A

Admin • 828.03K Points
Coach

Q. What does the 'each' method do in Ruby?

  • (A) Iterates over elements
  • (B) Sorts the elements
  • (C) Filters the elements
  • (D) Deletes elements

A

Admin • 828.03K Points
Coach

Q. Which of these is the correct way to define a symbol-to-string hash key?

  • (A) { 'key' => 'value' }
  • (B) { key: 'value' }
  • (C) { :key => 'value' }
  • (D) Both option2 and option3

A

Admin • 828.03K Points
Coach

Q. What is the result of 10 / 3 in Ruby?

  • (A) 3
  • (B) 3.33
  • (C) 3.0
  • (D) Error

A

Admin • 828.03K Points
Coach

Q. Which method converts a symbol to a string in Ruby?

  • (A) to_s
  • (B) to_str
  • (C) to_sym
  • (D) to_string

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