Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Ruby to Erlang Bridge And Runner
Erlang Ruby
Branch: master

Add MIT license

latest commit fb7f7c85e1
Tom Preston-Werner authored
Failed to load latest commit information.
LICENSE Add MIT license
README add readme
client.rb first commit
funs.erl first commit
json.erl first commit
rebar.erl first commit


  by Tom Preston-Werner

With Moore's Law about to crumble from beneath our feet, we all need to start
thinking about how to make use of those 64 core processors we'll be rockin' in
our laptops in a few years. Ruby is an amazing language for many tasks, but
sadly concurrent programming is not one of them. In preparation for the future
I could consider dropping Ruby altogether and find another more appropriate
language. But that would be madness. Ruby is awesome. What if I could still
write the bulk of my projects in Ruby, but farm out the threaded stuff to the
concurrency mercenary that is Erlang? That would be cool, right?

Consider a small Erlang module:

  -export([add/2, cat/2, fac/1]).

  add(A, B) ->
    A + B.
  cat(A, B) ->
    A ++ B.
  fac(N) ->
    fac(1, N).
  fac(Memo, 0) ->
  fac(Memo, N) ->
    fac(Memo * N, N - 1).

I'd like to be able to call these Erlang functions from my Ruby code without a
lot of fuss. Hmm, how's this for a low-fuss approach:

  require 'rebar'

  funs =, '', 5500)

  funs.add(1, 2)
  # => 3"foo", "bar")
  # => "foobar"

  # => 3628800

Wow, that would be nice. Good thing I just spent the last two days writing
some code to make it a reality!

The library is called Rebar (Ruby to Erlang Bridge And Runner). Rebar has two
parts: an Erlang server and a Ruby client. The server listens for JSON-RPC
requests, calls the specified Erlang function, and responds with a JSON-RPC
response. The Ruby client object simply accepts any method name, captures it
with method_missing, wraps everything up in a JSON-RPC request, fires it off,
waits for the response, and then extracts the result out of the JSON-RPC
response, returning it like a normal Ruby call.
Something went wrong with that request. Please try again.