Name

SingleForwardable — Selective delegation module

Synopsis

The SingleForwardable module provides more explicit method delegation for a specific object.

Required Library

require ‘forwardable’

Example

require 'forwardable'

# ...
g = Goo.new
g.extend SingleForwardable
g.def_delegator("@out", :puts)
g.puts("hello world")            # forward to @out.puts

Instance Methods

f.def_singleton_delegator(accessor, method[, alt=method])
f.def_delegator(accessor, method[, alt=method])

Defines delegation from method to accessor. If alt is specified, alt method is called instead of method.

f.def_singleton_delegators(accessor, method...)
f.def_delegators(accessor, method...)

Defines delegation to accessor for each method.

Get Ruby in a Nutshell 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.