Bird
0
0

Why does Ruby use the method lookup chain instead of searching only the object's class?

hard📝 Conceptual Q10 of 15
Ruby - Inheritance

Why does Ruby use the method lookup chain instead of searching only the object's class?

ATo make method calls slower for security
BTo support inheritance and module mixins for flexible code reuse
CTo limit methods to only those defined in the object's class
DTo avoid using modules in Ruby
Step-by-Step Solution
Solution:
  1. Step 1: Understand purpose of lookup chain

    Ruby's lookup chain allows methods from superclasses and included modules to be found.
  2. Step 2: Identify reason for this design

    This supports inheritance and mixins, enabling flexible and reusable code.
  3. Final Answer:

    To support inheritance and module mixins for flexible code reuse -> Option B
  4. Quick Check:

    Lookup chain enables inheritance and mixins [OK]
Quick Trick: Lookup chain enables flexible code reuse [OK]
Common Mistakes:
  • Thinking lookup chain slows code for security
  • Believing methods are limited to object's class only
  • Assuming Ruby avoids modules

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes