Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Load CommonJS Modules into Ruby (via therubyracer). hybridtheory.

branch: master

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .gitmodules
Octocat-spinner-32 Gemfile
Octocat-spinner-32 Gemfile.lock
Octocat-spinner-32 LICENSE
Octocat-spinner-32 Rakefile
Octocat-spinner-32 include_js.gemspec


Load CommonJS Modules into Ruby.

Currently it supports the CommonJS Modules 1.0 spec.

It uses therubyracer.


Writing a CommonJS Module in JavaScript

Inside 'helpers.js':

var a = 42; = function() {
  return 42;

Loading a CommonJS Module from Ruby

helpers = IncludeJS.require('helpers') # This returns a V8::Object # => 42

Loading a CommonJS Module as a Ruby Module

class App
  include IncludeJS.module('helpers')
end # => 42

You can set one root path from where to load .js files

IncludeJS.root_path = 'my/app/javascripts'

Have fun.

Running the specs

git submodule update --init
bundle install
bundle rspec spec    


Simple benchmarks are showing a noticeable gain of speed when using JS methods instead of native Ruby ones. While the Google V8 seems to be 10x faster than Ruby 1.8.7 it is still 4x as fast as Ruby 1.9.2

Something went wrong with that request. Please try again.