Class: Proc::Callable
- Inherits:
-
Composer::Callable
- Object
- Composer::Callable
- Proc::Callable
- Defined in:
- lib/proc/callable.rb
Instance Method Summary collapse
-
#call(input = input_omitted = true, **arguments) ⇒ Object
- public
-
Dispatches this callable context to proc using the client.
-
#each(input = input_omitted = true, **arguments, &block) ⇒ Object
- public
-
Dispatches this callable context to proc using the client, calling the given block once for each value.
-
#initialize(proc, client:, **kwargs) ⇒ Callable
constructor
A new instance of Callable.
Constructor Details
#initialize(proc, client:, **kwargs) ⇒ Callable
Returns a new instance of Callable.
7 8 9 10 11 |
# File 'lib/proc/callable.rb', line 7 def initialize(proc, client:, **kwargs) @client = client super(proc, **kwargs) end |
Instance Method Details
#call(input = input_omitted = true, **arguments) ⇒ Object
- public
-
Dispatches this callable context to proc using the client.
If a block is passed, it will be called to prior to dispatch and its result passed as a nested context.
17 18 19 20 21 22 23 24 25 |
# File 'lib/proc/callable.rb', line 17 def call(input = input_omitted = true, **arguments) if ::Kernel.block_given? arguments[:proc] = yield end callable = build_callable(input: input_omitted ? @input : input, arguments: @arguments.merge(arguments)) @client.call(@proc, callable.input, **callable.arguments) end |
#each(input = input_omitted = true, **arguments, &block) ⇒ Object
- public
-
Dispatches this callable context to proc using the client, calling the given block once for each value.
29 30 31 32 33 |
# File 'lib/proc/callable.rb', line 29 def each(input = input_omitted = true, **arguments, &block) callable = build_callable(input: input_omitted ? @input : input, arguments: @arguments.merge(arguments)) @client.call(@proc, callable.input, **callable.arguments, &block) end |