module DSLKit::Delegate
def delegate(method_name, obj, other_method_name = method_name)
end
delegate :method_here, :method_call, :method_there
class A
or:
end
delegate :method_here, :@obj, :method_there
class A
It's used like this:
instance variable or returned by a method call.
A method to easily delegate methods to an object, stored in an
def delegate(method_name, obj, other_method_name = method_name) raise ArgumentError, "obj wasn't defined" unless obj in only: define_method(method_name) do |*args, &block| instance_variable_get(obj).__send__(other_method_name, *args, &block) end obj = obj.to_s if obj[0] == ?@ class_eval <<-EOS def #{method_name}(*args, &block) instance_variable_get('#{obj}').__send__( '#{other_method_name}', *args, &block) end EOS else class_eval <<-EOS def #{method_name}(*args, &block) __send__('#{obj}').__send__( '#{other_method_name}', *args, &block) end EOS end end