2 ms·
Strictly speaking ruby, private only forbids calling the method in question with an explicit receiver. object_instance.private_method is obviously prohibited,
by route66 15y ago
Strictly speaking ruby, private only forbids calling the method in question with an explicit receiver.
object_instance.private_method is obviously prohibited, but so is self.private_method when called from another class method. The latter one is fine when private_method is called, without the self. To circumvent privateness in the other case ("calling an underscored method") you would have to say object_instance.send(:private_method).
- petercooper 15y agoLuckily there's also protected, which allows you to call with an explicit receiver, but only from an instance of the same class (or within its hierarchy).