Snarl - A JavaScript Bridge for JRuby
If you would like to use JavaScript directly from Ruby, check out Snarl. I just pushed its first public release to Gemcutter. Snarl is JRuby-only, as it uses Mozilla’s Rhino JavaScript engine to do its work.
First, make sure you’re using Gemcutter:
gem install gemcutter
gem tumble
Then, install and use:
gem install snarl
irb
> context = Snarl::JavascriptContext.new
> context.eval(“1+1”) # => 2
> context.eval(“var increment = function(i) { return i+1 };”)
> context.eval(“increment(3)”) # => 4
> context.load(“/path/to/js/lib.js”) # allows use of lib.js
> context.put(“foo”, “bar”)
> context.get(“foo”) # => “bar”