Bird
0
0

What does the method_added hook do in Ruby?

easy📝 Conceptual Q11 of 15
Ruby - Advanced Metaprogramming
What does the method_added hook do in Ruby?
AIt runs when a class is inherited by another class.
BIt runs automatically whenever a new instance method is defined in a class.
CIt runs when a method is called on an object.
DIt runs when a module is included in a class.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the purpose of method_added

    The method_added hook is a special method in Ruby that triggers automatically when a new instance method is defined inside a class.
  2. Step 2: Compare with other hooks

    Other hooks like inherited or included run on inheritance or module inclusion, not on method definition.
  3. Final Answer:

    It runs automatically whenever a new instance method is defined in a class. -> Option B
  4. Quick Check:

    method_added triggers on method definition [OK]
Quick Trick: Remember: method_added triggers on new instance methods [OK]
Common Mistakes:
  • Confusing method_added with inherited or included hooks
  • Thinking it runs when methods are called
  • Assuming it triggers on class creation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes