Methods

Files

DSLKit::Delegate

This module can be included into modules/classes to make the delegate method available.

Public Instance Methods

delegate(method_name, obj, other_method_name = method_name) click to toggle source

A method to easily delegate methods to an object, stored in an instance variable or returned by a method call.

It’s used like this:

  class A
    delegate :method_here, :@obj, :method_there
  end

or:

  class A
    delegate :method_here, :method_call, :method_there
  end

other_method_name defaults to method_name, if it wasn’t given.

# File lib/dslkit/polite.rb, line 524
    def delegate(method_name, obj, other_method_name = method_name)
      raise ArgumentError, "obj wasn't defined" unless obj
??
      obj = obj.to_s
      if obj[0] == ?@
        class_eval "def \#{method_name}(*args, &block)\ninstance_variable_get('\#{obj}').__send__(\n'\#{other_method_name}', *args, &block)\nend\n"
      else
        class_eval "def \#{method_name}(*args, &block)\n__send__('\#{obj}').__send__(\n'\#{other_method_name}', *args, &block)\nend\n"
      end
    end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.