Flow Based Programming in Ruby (or "Pipes in Ruby").

(The next step after "DeadlySerious"[] gem)

I think I finally figured out why components in a flow based program are not "functions" or "methods". I believe the main point is the ability to pass its own result forward several times.

| component A | --> | component B |

"A" can call "B" an arbitrary number of times. That works very differently of a function or method "return"

So, adding to the other benefits, as easy parallelism and high modificability, I strongly believe the paradigm itself is really strong for pratical programs.

The main goal of this gem is to provide the foundation of a "killer application" based solely on pipes (a new web framework, probably :p). Other than that, I'm using it to study the paradigm.

The plan is to keep this gem minimal and add new features in new (other) gems.


Add this line to your application's Gemfile:

gem 'rewire'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rewire


The result of the computations is always collected in an object. The object ("output" below), needs to respond to the "<<" method, so arrays, strings and IOs can be used.

require 'rewire'

# Declare the component.
# It receives 2 parameters, the output ("out" below) and the packet,
# meaning the data passed to the pipe.
upcaser = { |out, packet| out << packet.upcase }

output = []

# Connect pipe to output.
pipe =  upcaser | output

# Pass things to the pipe.
pipe << 'test'
pipe << 'another test'

# Output collects results.
puts output # => ['TEST', 'ANOTHER TEST']

A more complex example

require 'rewire'

pipeline =
  Pipe { |out, packet| 


  • Fiber based pipes
  • Process based pipes


  1. Fork it ( )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request