5.3. Deploying method-access rules
As you’ve seen, the main business of a Ruby program is to send messages to objects. And the main business of an object is to respond to messages. Sometimes, an object wants to be able to send itself messages that it doesn’t want anyone else to be able to send it. For this scenario, Ruby provides the ability to make a method private.
There are two access levels other than private: protected, which is a slight variation on private, and public. Public is the default access level; if you don’t specify that a method is protected or private, it’s public. Public instance methods are the common currency of Ruby programming. Most of the messages you send to objects are calling public methods.
We’ll focus here on methods ...
Get The Well-Grounded Rubyist, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.