Bird
0
0

How can you use include to add instance methods from a module and also override one method in the class while still calling the original module method?

hard📝 Application Q9 of 15
Ruby - Modules and Mixins
How can you use include to add instance methods from a module and also override one method in the class while still calling the original module method?
AInherit from the module and override method
BInclude the module, define method in class, call module method by name
CExtend the module and define method in class
DInclude the module, define method in class, use <code>super</code> to call module method
Step-by-Step Solution
Solution:
  1. Step 1: Include module to add instance methods

    Use include to add module methods as instance methods.
  2. Step 2: Override method in class and call original with super

    Define method with same name in class and call super to invoke module's method.
  3. Final Answer:

    Include the module, define method in class, use super to call module method -> Option D
  4. Quick Check:

    Override with super calls original module method [OK]
Quick Trick: Use super in overridden method to call module method [OK]
Common Mistakes:
  • Calling module method by name instead of super
  • Using extend instead of include
  • Trying to inherit from module

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes