Type:
Class

This library provides three different ways to delegate method calls to an object. The easiest to use is SimpleDelegator. Pass an object to the constructor and all methods supported by the object will be delegated. This object can be changed later.

Going a step further, the top level DelegateClass method allows you to easily setup delegation through class inheritance. This is considerably more flexible and thus probably the most common use for this library.

Finally, if you need full control over the delegation scheme, you can inherit from the abstract class Delegator and customize as needed. (If you find yourself needing this control, have a look at Forwardable which is also in the standard library. It may suit your needs better.)

SimpleDelegator's implementation serves as a nice example if the use of Delegator:

class SimpleDelegator < Delegator
  def initialize(obj)
    super                  # pass obj to Delegator constructor, required
    @delegate_sd_obj = obj # store obj for future use
  end

  def __getobj__
    @delegate_sd_obj # return object we are delegating to, required
  end

  def __setobj__(obj)
    @delegate_sd_obj = obj # change delegation object,
                           # a feature we're providing
  end
end

Notes

Be advised, RDoc will not detect delegated methods.

protected_methods

protected_methods(all=true) Instance Public methods Returns the methods available

2015-04-03 00:17:46
method_missing

method_missing(m, *args, &block) Instance Public methods Handles the magic

2015-04-03 00:12:52
untrust

untrust Instance Public methods Untrust both the object returned by _getobj_

2015-04-03 00:41:21
!

!=(obj) Instance Public methods Returns true if two objects are not considered

2015-04-02 23:42:04
==

==(obj) Instance Public methods Returns true if two objects are considered of

2015-04-02 23:47:10
marshal_dump

marshal_dump() Instance Public methods Serialization support for the object

2015-04-03 00:06:11
trust

trust Instance Public methods Trust both the object returned by _getobj_

2015-04-03 00:34:42
respond_to_missing?

respond_to_missing?(m, include_private) Instance Public methods Checks for a

2015-04-03 00:21:36
freeze

freeze Instance Public methods Freeze both the object returned by _getobj_

2015-04-03 00:03:03
marshal_load

marshal_load(data) Instance Public methods Reinitializes delegation from a serialized

2015-04-03 00:08:34