Specifying Access Control
When designing the interface for a class, it’s important to consider how much of your class you’ll expose to the outside world. Allow too much access into your class, and you risk increasing the amount that different classes depend on each other’s internal implementation, which is called coupling. Users of your class will be tempted to rely on details of your class’s implementation rather than on its logical interface. The good news is that the only easy way to change an object’s state in Ruby is by calling one of its methods. If you control access to the methods, you control access to the object. A good rule of thumb is never to expose methods that could leave an object in an invalid state.
Ruby gives you three levels ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access