Bird
0
0

Identify the error in this Ruby module method code:

medium📝 Debug Q14 of 15
Ruby - Modules and Mixins
Identify the error in this Ruby module method code:
module Greetings
  def greet
    "Hello!"
  end
end

puts Greetings.greet
AMethod greet is not defined as a module method
BModule name is incorrect
CMissing parentheses in method call
DSyntax error in method body
Step-by-Step Solution
Solution:
  1. Step 1: Check method definition inside module

    The method greet is defined without self., so it is an instance method, not a module method.
  2. Step 2: Understand method call

    Calling Greetings.greet tries to call a module method, but none exists, causing an error.
  3. Final Answer:

    Method greet is not defined as a module method -> Option A
  4. Quick Check:

    Missing self. means no module method [OK]
Quick Trick: Add self. to define module methods [OK]
Common Mistakes:
  • Defining instance methods instead of module methods
  • Calling module method without defining it
  • Assuming parentheses are required in method call

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes