Before I read this article, I thought access control in Ruby worked like this:
public
- can be accessed by any object (e.g.Obj.new.public_method
)protected
- can only be accessed from within the object itself, as well as any subclassesprivate
- same as protected, but the method doesn't exist in subclasses
However, it appears that protected
and private
act the same, except for the fact that you can't call private
methods with an explicit receiver (i.e. self.protected_method
works, but self.private_method
doesn't).
What's the point of this? When is there a scenario when you wouldn't want your method called with an explicit receiver?
Question&Answers:os