πŸ“Š Ruby
Q. Which method returns the first element of an array in Ruby?
  • (A) first
  • (B) head
  • (C) start
  • (D) begin
πŸ’¬ Discuss
βœ… Correct Answer: (A) first

Explanation: The first method returns the first element of an array.

πŸ“Š Ruby
Q. Which keyword is used to raise an exception in Ruby?
  • (A) throw
  • (B) raise
  • (C) catch
  • (D) error
πŸ’¬ Discuss
βœ… Correct Answer: (B) raise

Explanation: The raise keyword is used to throw an exception.

πŸ“Š Ruby
Q. Which keyword is used to exit a loop in Ruby?
  • (A) break
  • (B) stop
  • (C) exit
  • (D) end
πŸ’¬ Discuss
βœ… Correct Answer: (A) break

Explanation: The break keyword terminates a loop.

πŸ“Š Ruby
Q. Which method converts a string to uppercase in Ruby?
  • (A) upcase
  • (B) uppercase
  • (C) toUpperCase
  • (D) capitalize
πŸ’¬ Discuss
βœ… Correct Answer: (A) upcase

Explanation: The upcase method converts a string to uppercase.

πŸ“Š Ruby
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
πŸ’¬ Discuss
βœ… Correct Answer: (A) Starting with uppercase letter

Explanation: Constants begin with an uppercase letter in Ruby.

πŸ“Š Ruby
Q. What is the output of 'nil.nil?' in Ruby?
  • (A) true
  • (B) false
  • (C) nil
  • (D) error
πŸ’¬ Discuss
βœ… Correct Answer: (A) true

Explanation: Calling nil? on nil returns true.

πŸ“Š Ruby
Q. Which method is used to check if an array includes a specific element?
  • (A) include?
  • (B) has?
  • (C) contains?
  • (D) exists?
πŸ’¬ Discuss
βœ… Correct Answer: (A) include?

Explanation: The include? method returns true if the element exists in the array.

πŸ“Š Ruby
Q. What does the 'each' method do in Ruby?
  • (A) Iterates over elements
  • (B) Sorts the elements
  • (C) Filters the elements
  • (D) Deletes elements
πŸ’¬ Discuss
βœ… Correct Answer: (A) Iterates over elements

Explanation: The each method iterates over each element in a collection.

πŸ“Š Ruby
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
πŸ’¬ Discuss
βœ… Correct Answer: (D) Both option2 and option3

Explanation: Ruby supports both new and old syntax for symbol keys.

πŸ“Š Ruby
Q. What is the result of 10 / 3 in Ruby?
  • (A) 3
  • (B) 3.33
  • (C) 3.0
  • (D) Error
πŸ’¬ Discuss
βœ… Correct Answer: (A) 3

Explanation: Integer division truncates decimal part in Ruby.