Observable
The Observer pattern, also known as Publish/Subscribe, provides a simple mechanism for one object (the source) to inform a set of interested third-party objects when its state changes. In the Ruby implementation, the notifying class mixes in the module Observable, which provides the methods for managing the associated observer objects. The observers must implement the update method to receive notifications.
The way this works is that the class that’s sending the notifications adds include Observable. To add subscribers to the notifications, you call Observable#add_observer(observer, method = :update). The observer is an object that receives a notification, and method is the method that’s automatically called when a notification is ...
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