Class: Wolflow::Operators::Operation
- Defined in:
- lib/wolflow/operators/operation.rb
Class Method Summary collapse
Instance Method Summary collapse
- #call(task) ⇒ Object
-
#initialize(op:, members:, **args) ⇒ Operation
constructor
A new instance of Operation.
- #to_hash ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(op:, members:, **args) ⇒ Operation
Returns a new instance of Operation.
6 7 8 9 10 |
# File 'lib/wolflow/operators/operation.rb', line 6 def initialize(op:, members:, **args) @op = op @members = Array(members) super(**args) end |
Class Method Details
Instance Method Details
#call(task) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/wolflow/operators/operation.rb', line 12 def call(task) reducer, *members = @members return unless reducer reducer = reducer.call(task) members.reduce(reducer) do |acc, member| acc.__send__(@op, member.call(task)) end end |
#to_hash ⇒ Object
24 25 26 27 28 29 |
# File 'lib/wolflow/operators/operation.rb', line 24 def to_hash hs = super hs[:op] = @op hs[:members] = @members.map(&:to_hash) hs end |