Bird
0
0

Why does Ruby restrict calling private methods with an explicit receiver, even if it is self?

hard📝 Conceptual Q10 of 15
Ruby - Inheritance
Why does Ruby restrict calling private methods with an explicit receiver, even if it is self?
ATo enforce encapsulation by preventing external access
BTo avoid ambiguity in method lookup and maintain clear intent
CTo allow only internal calls without specifying the object
DBecause private methods are actually public under the hood
Step-by-Step Solution
Solution:
  1. Step 1: Understand Ruby's private method design

    Ruby restricts explicit receiver calls to avoid ambiguity and enforce clear intent that private methods are internal.
  2. Step 2: Evaluate options

    To avoid ambiguity in method lookup and maintain clear intent correctly explains the design choice. Options A and B are partially true but incomplete. Because private methods are actually public under the hood is false.
  3. Final Answer:

    To avoid ambiguity in method lookup and maintain clear intent -> Option B
  4. Quick Check:

    Reason for private call restriction = To avoid ambiguity in method lookup and maintain clear intent [OK]
Quick Trick: Private methods disallow explicit receiver to keep calls unambiguous [OK]
Common Mistakes:
  • Thinking restriction is only for encapsulation
  • Assuming private methods are public internally
  • Ignoring method lookup clarity reasons

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes