# delegate.rb

Path: | delegate.rb
Last Update: | Thu Dec 04 21:22:52 GMT+10:00 2003

     Delegation class that delegates even methods defined in super class,

which can not be covered with normal method_missing hack.

     Delegator is the abstract delegation class. Need to redefine

`getobj’ method in the subclass. SimpleDelegator is the concrete subclass for simple delegation.

Usage:

      foo = Object.new
      foo2 = SimpleDelegator.new(foo)
      foo.hash == foo2.hash # => false

      Foo = DelegateClass(Array)

     class ExtArray<DelegateClass(Array)
       ...
     end

## Methods

DelegateClass

## Constants

Delegater | = | Delegator
| backward compatibility ^_^;;;
SimpleDelegater | = | SimpleDelegator

## Classes and Modules

Class Delegator
Class ExtArray
Class SimpleDelegator

## Public Instance methods

DelegateClass(superclass)

[Source]

    # File delegate.rb, line 85
    def DelegateClass(superclass)
      klass = Class.new
      methods = superclass.public_instance_methods(true)
      methods -= ::Kernel.public_instance_methods(false)
      methods |= ["to_s","to_a","inspect","==","=~","==="]
      klass.module_eval "def initialize(obj)\n@obj = obj\nend\n"
      for method in methods
        begin
          klass.module_eval "def \#{method}(*args, &block)\nbegin\n@obj.__send__(:\#{method}, *args, &block)\nrescue\n$@[0,2] = nil\nraise\nend\nend\n"
        rescue SyntaxError
          raise NameError, "invalid identifier %s" % method, caller(3)
        end
      end
      return klass;
    end

[Validate]