ExecJS supports these runtimes:
- therubyracer - Google V8 embedded within Ruby
- therubyrhino - Mozilla Rhino embedded within JRuby
- Microsoft Windows Script Host (JScript)
A short example:
ExecJS.eval "'red yellow blue'.split(' ')"
# => ["red", "yellow", "blue"]
A longer example, demonstrating how to invoke the CoffeeScript compiler:
``` ruby require “execjs” require “open-uri” source = open(“http://coffeescript.org/extras/coffee-script.js”).read
context = ExecJS.compile(source) context.call(“CoffeeScript.compile”, “square = (x) -> x * x”, bare: true) # => “var square;\nsquare = function(x) return x * x;\n;” ```
$ gem install execjs
Why can’t I use CommonJS
require() inside ExecJS?
Copyright (c) 2014 Sam Stephenson and Josh Peek.
Released under the MIT license. See
LICENSE for details.