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:
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.
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.
Final Answer:
To avoid ambiguity in method lookup and maintain clear intent -> Option B
Quick Check:
Reason for private call restriction = To avoid ambiguity in method lookup and maintain clear intent [OK]