class QB::Util::Decorators::EnumFor

Wrap a method that yields, returning an {Enumerator} if no block is given.

Implements the common “enum_for” pattern:

def f
  return enum_for( __method__ ) unless block_given?
  yield 1
  # ...
end

Public Instance Methods

call(target, receiver, *args, &block) click to toggle source

@param [Method] target

The decorated method, already bound to the receiver.

The `method_decorators` gem calls this `orig`, but I thought `target`
made more sense.

@param [*] receiver

The object that will receive the call to `target`.

The `method_decorators` gem calls this `this`, but I thought `receiver`
made more sense.

It's just `target.receiver`, but the API is how it is.

@param [Array] *args

Any arguments the decorated method was called with.

@param [Proc?] &block

The block the decorated method was called with (if any).
# File lib/qb/util/decorators.rb, line 70
def call target, receiver, *args, &block
  if block
    target.call *args, &block
  else
    receiver.enum_for target.name, *args
  end
end