Bird
0
0

Identify the error in this Ruby code:

medium📝 Debug Q6 of 15
Ruby - Modules and Mixins
Identify the error in this Ruby code:
module M
  def greet
    "Hi"
  end
end

class E
  include M
  def greet
    super + " there"
  end
end

puts E.new.greet
AError: Missing parentheses in method call
BError: super called without a method to override
CError: Module methods cannot be called with super
DNo error; output is 'Hi there'
Step-by-Step Solution
Solution:
  1. Step 1: Understand super with modules

    When a class method calls super, it looks up the method in included modules.
  2. Step 2: Check method lookup

    Class E's greet calls super, which calls greet in module M returning "Hi".
  3. Final Answer:

    No error; output is 'Hi there' -> Option D
  4. Quick Check:

    super calls module method correctly = D [OK]
Quick Trick: super works with included module methods [OK]
Common Mistakes:
  • Thinking super can't call module methods
  • Expecting syntax error on super
  • Confusing method overriding rules

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes