class Proc::Composer::Composition
Attributes
arguments[R]
callables[R]
input[R]
Public Class Methods
new(input:, callables: [], arguments: {})
click to toggle source
# File lib/proc/composer/composition.rb, line 13 def initialize(input:, callables: [], arguments: {}) @input = input @callables = callables @arguments = arguments end
Public Instance Methods
<<(callable)
click to toggle source
# File lib/proc/composer/composition.rb, line 54 def <<(callable) case callable when Composition merge(callable) when Callable @callables << callable end end
>>(other)
click to toggle source
- public
-
Returns a composition built from this composition and another callable.
# File lib/proc/composer/composition.rb, line 47 def >>(other) composed = dup composed << other composed end
Also aliased as: |
compose(*others)
click to toggle source
- public
-
Returns a composition from this composition and one or more other callables.
# File lib/proc/composer/composition.rb, line 39 def compose(*others) composed = dup others.each { |other| composed << other } composed end
initialize_copy(_)
click to toggle source
# File lib/proc/composer/composition.rb, line 19 def initialize_copy(_) @callables = @callables.dup end
merge(composition)
click to toggle source
# File lib/proc/composer/composition.rb, line 83 def merge(composition) raise ArgumentError, "expected a composition" unless composition.is_a?(self.class) @callables.concat(composition.callables) @arguments.merge!(composition.arguments) end
serialize()
click to toggle source
# File lib/proc/composer/composition.rb, line 63 def serialize serialized = ["{}"] unless Proc::Composer.undefined?(@input) serialized << [">>", serialized_input] end serialized + serialized_arguments + @callables.map { |callable| callable.serialize(unwrapped: true) } end
serialized_arguments()
click to toggle source
# File lib/proc/composer/composition.rb, line 77 def serialized_arguments @arguments.map { |key, value| ["$$", key.to_s, serialize_value(value)] } end
serialized_input()
click to toggle source
# File lib/proc/composer/composition.rb, line 73 def serialized_input serialize_value(@input) end
with(input = input_omitted = true, **arguments) { || ... }
click to toggle source
- public
-
Creates a new composition based on this one, with a new input and/or arguments.
# File lib/proc/composer/composition.rb, line 25 def with(input = input_omitted = true, **arguments) if block_given? arguments[:proc] = yield end build_composition( input: input_omitted ? @input : input, arguments: @arguments.merge(arguments), callables: @callables.dup ) end
Private Instance Methods
build_composition(callables:, input:, arguments:)
click to toggle source
# File lib/proc/composer/composition.rb, line 103 def build_composition(callables:, input:, arguments:) self.class.new(input: input, callables: callables, arguments: arguments) end
serialize_value(value)
click to toggle source
# File lib/proc/composer/composition.rb, line 90 def serialize_value(value) case value when Symbol ["@@", value.to_s, {}] else if value.respond_to?(:serialize) value.serialize else ["%%", value] end end end