Bird
0
0

How can you combine two modules M1 and M2 so a class H can include both and resolve method conflicts explicitly?

hard📝 Application Q9 of 15
Ruby - Modules and Mixins
How can you combine two modules M1 and M2 so a class H can include both and resolve method conflicts explicitly?
ACreate a new module that includes M1 and M2, then include it in H
BInclude M1 and M2 directly in H and rely on last included wins
CDefine methods in H that call super to resolve conflicts
DUse multiple inheritance with classes instead of modules
Step-by-Step Solution
Solution:
  1. Step 1: Understand conflict resolution

    Including multiple modules with same method names causes last included to override.
  2. Step 2: Use explicit method in class

    Defining method in class H that calls super can combine or choose which module method to use.
  3. Final Answer:

    Define methods in H that call super to resolve conflicts -> Option C
  4. Quick Check:

    Explicit conflict resolution via super = D [OK]
Quick Trick: Use class methods with super to resolve module conflicts [OK]
Common Mistakes:
  • Relying only on last included module
  • Trying multiple inheritance with classes
  • Not defining conflict-resolving methods

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes