Skip to content

sinisterchipmunk/node.rb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node.rb

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

Prerequisites

You need the following before you can install node.rb:

  • Ruby 1.8.7 or newer (including all flavors of Ruby 1.9)

  • Node.js 0.2.0

  • Python 2.4 for compiling (but Node needs this too so it probably isn’t an issue)

Node.js currently only runs on Linux and Mac machines, so I don’t think this will go well for you if you’re on Windows. But hey, I’ve been wrong before…

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.

Testbeds

I’ve tested this gem on various combinations of the following platforms:

  • Ruby 1.8.7 on Mac

  • Ruby 1.9.2 on Mac

  • Ruby 1.8.7 on Ubuntu 10.4

  • Ruby 1.9.1 on Ubuntu 10.4

  • Ruby 1.9.2 on Ubuntu 10.4

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.

About

Embeds a Ruby interpreter into Node.js, so you can execute Ruby code from within your Node-based JavaScript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published