Bird
0
0

Why does including a module with methods defined as self.method_name not add those methods as instance methods to a class?

hard📝 Conceptual Q10 of 15
Ruby - Modules and Mixins
Why does including a module with methods defined as self.method_name not add those methods as instance methods to a class?
ABecause self.method_name defines private methods
BBecause methods defined with self are module's singleton methods, not instance methods
CBecause include only works with instance variables
DBecause Ruby does not allow modules to have methods
Step-by-Step Solution
Solution:
  1. Step 1: Understand method definition with self

    Methods defined as self.method_name are singleton (class) methods of the module.
  2. Step 2: Effect of include on methods

    Including a module adds its instance methods to the class, but singleton methods are not included.
  3. Final Answer:

    Because methods defined with self are module's singleton methods, not instance methods -> Option B
  4. Quick Check:

    Self.method_name = module class method, not included [OK]
Quick Trick: Self.method_name defines module class methods, not instance methods [OK]
Common Mistakes:
  • Thinking include adds module class methods
  • Confusing instance variables with methods
  • Believing Ruby disallows module methods

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes