Bird
0
0

In Ruby, what is the effect of using include with a module inside a class definition?

easy📝 Conceptual Q1 of 15
Ruby - Modules and Mixins
In Ruby, what is the effect of using include with a module inside a class definition?
AIt inherits the module as a superclass of the class.
BIt adds the module's methods as class methods of the class.
CIt adds the module's instance methods as instance methods of the class.
DIt creates a new module inside the class.
Step-by-Step Solution
Solution:
  1. Step 1: Understand include

    In Ruby, include mixes in a module's instance methods into the target class as instance methods.
  2. Step 2: Differentiate from extend

    Using extend adds module methods as class methods, not instance methods.
  3. Final Answer:

    It adds the module's instance methods as instance methods of the class. -> Option C
  4. Quick Check:

    Instance methods from modules become instance methods in classes with include. [OK]
Quick Trick: Include adds instance methods from modules to classes [OK]
Common Mistakes:
  • Confusing include with extend
  • Thinking include adds class methods
  • Assuming include creates inheritance

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes