node.rb

Embeds a Ruby interpreter (www.ruby-lang.org) into Node.js (www.nodejs.org) for your coding pleasure.

Installation

gem install node.rb

Usage

To create a Ruby context within your node.js application, do so like this:

var ruby = require('ruby');
ruby.eval('p 1+1');

Execution

For your convenience, the node.rb gem ships with an executable so that you can just:

node-rb filename.js

To execute with the stock node.js executable:

NODE_PATH=$NODE_PATH:path/to/node.rb node filename.js

NODE_PATH is a standard option in node.js and is a simple environment variable. That means you can do this:

export NODE_PATH=$NODE_PATH:path/to/node.rb
node filename.js

And finally, though I’m not sure why you’d want to do this, you can invoke Node from within Ruby:

require 'node-rb'
n = Node.new("path/to/javascript.js")
n.run

That’s roughly equivalent to running the node-rb command directly.

Roadmap

There are plans to expose Node to Ruby and vice versa so that objects can travel between the two contexts, but that’s not available at this time.

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright © 2010 Colin MacKenzie IV. See LICENSE for details.