πŸ“Š Ruby
Q. What is memoization in Ruby?
  • (A) Evaluating code at runtime based on user input
  • (B) Creating anonymous functions that can be called later
  • (C) Dynamically defining methods based on certain conditions
  • (D) Caching the return value of a method for future invocations
πŸ’¬ Discuss
βœ… Correct Answer: (D) Caching the return value of a method for future invocations
πŸ“Š Ruby
Q. What is the purpose of the instance_eval method in Ruby?
  • (A) Evaluating a block of code within the context of the current instance
  • (B) Dynamically defining methods on a specific instance
  • (C) Evaluating a block of code within the context of a specific object
  • (D) Accessing the instance variables of a class from within a class method
πŸ’¬ Discuss
βœ… Correct Answer: (C) Evaluating a block of code within the context of a specific object
πŸ“Š Ruby
Q. What does the term "monkey patching" refer to in Ruby?
  • (A) Assigning custom methods to specific objects
  • (B) Modifying or extending existing classes or modules at runtime
  • (C) Overriding built-in methods with custom implementations
  • (D) Assigning custom methods to specific objects
πŸ’¬ Discuss
βœ… Correct Answer: (B) Modifying or extending existing classes or modules at runtime
πŸ“Š Ruby
Q. What is the file extension for Ruby files?
  • (A) .rb
  • (B) .ru
  • (C) .rby
  • (D) .ruby
πŸ’¬ Discuss
βœ… Correct Answer: (A) .rb

Explanation: Ruby source code files use the .rb file extension.

πŸ“Š Ruby
Q. Which method is used to print output in Ruby?
  • (A) console.log
  • (B) print
  • (C) echo
  • (D) printf
πŸ’¬ Discuss
βœ… Correct Answer: (B) print

Explanation: The print method outputs data to the screen in Ruby.

πŸ“Š Ruby
Q. How do you define a function (method) in Ruby?
  • (A) def functionName; end
  • (B) function functionName() {}
  • (C) def functionName() end
  • (D) func functionName {}
πŸ’¬ Discuss
βœ… Correct Answer: (C) def functionName() end

Explanation: In Ruby, methods are defined using 'def' followed by the method name and 'end' to close.

πŸ“Š Ruby
Q. How can you create an array in Ruby?
  • (A) [1, 2, 3]
  • (B) (1, 2, 3)
  • (C) {1, 2, 3}
  • (D) <1, 2, 3>
πŸ’¬ Discuss
βœ… Correct Answer: (A) [1, 2, 3]

Explanation: Arrays in Ruby are created using square brackets.

πŸ“Š Ruby
Q. Which keyword is used to create a class in Ruby?
  • (A) class
  • (B) def
  • (C) module
  • (D) object
πŸ’¬ Discuss
βœ… Correct Answer: (A) class

Explanation: 'class' keyword is used to define a class in Ruby.

πŸ“Š Ruby
Q. What will 'puts' method do in Ruby?
  • (A) Print text without a newline
  • (B) Print text with a newline
  • (C) Store text in a variable
  • (D) Comment the text
πŸ’¬ Discuss
βœ… Correct Answer: (B) Print text with a newline

Explanation: 'puts' prints the output followed by a newline.

πŸ“Š Ruby
Q. Which symbol is used to denote a comment in Ruby?
  • (A) //
  • (B) #
  • (C) <!-- -->
  • (D) /* */
πŸ’¬ Discuss
βœ… Correct Answer: (B) #

Explanation: In Ruby, comments start with the '#' symbol.