Delegator and SimpleDelegator
Object delegation is a way of composing objects—extending an object with the capabilities of another—at runtime. The Ruby Delegator class implements a simple but powerful delegation scheme, where requests are automatically forwarded from a master class to delegates or their ancestors and where the delegate can be changed at runtime with a single method call. The class SimpleDelegator is an implementation of Delegator that’s good enough for most purposes.
The typical use of SimpleDelegator is as a decorator. You create a class as a subclass of SimpleDelegator. You create new instances of the simple delegator class by passing it an existing instance of another class. When you call a method on the delegator, it’ll ...
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