Method: SingleForwardable#def_single_delegator

Defined in:
lib/forwardable.rb

#def_single_delegator(accessor, method, ali = method) ⇒ Object Also known as: def_delegator

:call-seq:

def_single_delegator(accessor, method, new_name=method)

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



271
272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/forwardable.rb', line 271

def def_single_delegator(accessor, method, ali = method)
  str = %{
    def #{ali}(*args, &block)
      begin
        #{accessor}.__send__(:#{method}, *args, &block)
      rescue Exception
        [email protected]_if{|s| Forwardable::FILE_REGEXP =~ s} unless Forwardable::debug
        ::Kernel::raise
      end
    end
  }

  instance_eval(str, __FILE__, __LINE__)
end