Bird
0
0

Identify the error in the following Ruby code that tries to use a module as a mixin:

medium📝 Debug Q14 of 15
Ruby - Modules and Mixins
Identify the error in the following Ruby code that tries to use a module as a mixin:
module Helper
  def help
    "Helping"
  end
end

class User
  extend Helper
end

puts User.new.help
AUsing extend instead of include causes NoMethodError on instance
BModule Helper is not defined properly
CUser class should be a module
Dhelp method should be a class method
Step-by-Step Solution
Solution:
  1. Step 1: Understand extend vs include

    extend Helper adds methods as class methods, not instance methods.
  2. Step 2: Analyze method call on instance

    User.new.help calls help on an instance, but method is only on class, causing NoMethodError.
  3. Final Answer:

    Using extend instead of include causes NoMethodError on instance -> Option A
  4. Quick Check:

    extend adds class methods, not instance methods [OK]
Quick Trick: Use include for instance methods, extend for class methods [OK]
Common Mistakes:
  • Confusing extend and include
  • Calling instance method on class method only
  • Thinking module definition is wrong

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes