Class: QB::Util::Decorators::EnumFor

Inherits:
MethodDecorators::Decorator
  • Object
show all
Defined in:
lib/qb/util/decorators.rb

Overview

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

Instance Method Summary collapse

Instance Method Details

#call(target, receiver, *args, &block) ⇒ Object

Parameters:

  • target (Method)

    The decorated method, already bound to the receiver.

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

  • 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.

  • *args (Array)

    Any arguments the decorated method was called with.

  • &block (Proc?)

    The block the decorated method was called with (if any).



70
71
72
73
74
75
76
# 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