Module

SingleForwardable

Inheritance

The SingleForwardable module provides delegation of specified methods to a designated object, using the methods def_delegator and def_delegators. This module is similar to Forwardable, but it works on objects themselves, instead of their defining classes.

Also see the example at forwardable.rb.

Methods

Instance

Visibility Signature
public def_delegator (accessor, method, ali = method)
public def_delegators (accessor, *methods)
public def_singleton_delegator (accessor, method, ali = method)
public def_singleton_delegators (accessor, *methods)

Instance Method Detail

def_delegator(accessor, method, ali = method)

def_delegators(accessor, *methods)

def_singleton_delegator(accessor, method, ali = method)

Defines a method method which delegates to obj (i.e. it calls the method of the same name in obj). If new_name is provided, it is used as the name for the delegate method.

See the example at forwardable.rb.

def_singleton_delegators(accessor, *methods)

Shortcut for defining multiple delegator methods, but with no provision for using a different name. The following two code samples have the same effect:

  single_forwardable.def_delegators :@records, :size, :<<, :map

  single_forwardable.def_delegator :@records, :size
  single_forwardable.def_delegator :@records, :<<
  single_forwardable.def_delegator :@records, :map

See the example at forwardable.rb.