This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
| name | age | message | |
|---|---|---|---|
| |
README.textile | Fri May 22 09:40:09 -0700 2009 | |
| |
lib/ | Fri May 22 09:34:08 -0700 2009 | |
| |
sample.rb | Fri May 22 09:34:08 -0700 2009 | |
| |
test/ | Wed May 20 20:30:20 -0700 2009 |
README.textile
rinterface: Ruby to Erlang client
rinterface is a pure Ruby client that can send RPC calls to an Erlang node. It’s very much a work in progress.
Requirements
- Erlang 12B-5
- Ruby
- Ruby gems
- Eventmachine
Try it out
1. Open a terminal, Cd into the test directory and run: ‘make’ ‘make run’This will start the erlang node named ‘math’
2. Open another terminal, and run: ‘ruby sample.rb’How to use?
In your Ruby code, make a call to the Erlang node like this:
Erlang::Node(nodename,module,function,args) => [:ok,Response] | [:badprc,Reason]
r = Erlang::Node.rpc("math","math_server","add",[10,20])
if r[0] == :badrpc
puts "Got and Error. Reason #{r[1]}"
else
puts "Success: #{r[1]}"
end
Where:
- math is the node name (the -sname of the Erlang node)
- math_server is the name of the module
- add is the funtion to call
- [10,20] is an array of arguments to pass to the function
The result will always be an Array of the form:
[:ok,Response] where Response is the result from the Erlang or [:badrpc,Reason] where Reason is the ‘why’ it failed
So you wanna call Erlang from your Rails app…
Here’s a quick and simple example. Make sure you put the rinterface lib into RAILS_ROOT/lib and start the math_server in ‘test’
In the controller:
controllers/math_controller.rb
require "lib/rinterface"
class MathController < ApplicationController
def index
a = params[:a]
b = params[:b]
r = Erlang::Node.rpc("math","math_server","add",[a.to_i,b.to_i])
if r[0] == :badrpc
@result = "Error"
else
@result = r[1]
end
end
end
Finally, add a template for the view, and try ‘http://localhost:3000/math?a=2&b=3’.
This is not ideal yet and not something I’d use yet in production, but it’s a starting point for experimenting.







