Class: Datapipes::Tube
- Inherits:
-
Object
- Object
- Datapipes::Tube
- Defined in:
- lib/datapipes/tube.rb
Overview
Tube takes effect data which passes through pipe.
Build your own tube logic in ‘run` method.
Instance Method Summary collapse
-
#>>(op2) ⇒ Object
_>>_ is used to compose tubes.
-
#run(data) ⇒ Object
Override this in sub class.
Instance Method Details
#>>(op2) ⇒ Object
_>>_ is used to compose tubes. See usage in examples.
Tube composition satisfies associative law. See more in spec.
9 10 11 12 13 14 15 16 |
# File 'lib/datapipes/tube.rb', line 9 def >>(op2) op1 = self Tube.new.tap do |o| o.define_singleton_method(:run) do |data| op2.run(op1.run(data)) end end end |
#run(data) ⇒ Object
Override this in sub class.
run recieves any data, so you have to ignore unexpected data.
def run(data)
if accept? data
[data, data, data]
else
data
end
end
def accept?(data)
data.is_a? Integer and data > 3
end
Don’t forget to return data in else clause.
36 37 38 |
# File 'lib/datapipes/tube.rb', line 36 def run(data) data end |