Ruby2JS

Ruby2JS is an extensible Ruby to modern JavaScript transpiler you can use in production today.

Get Started Try It Online!

Ruby2JS is for Ruby developers who want to produce JavaScript that looks hand-crafted, rather than machine generated. You can convert Ruby-like syntax and semantics as cleanly and “natively” as possible. This means that (most of the time) you’ll get a line-by-line, 1:1 correlation between your source code and the JS output.

For example:

class MyClass
  # Cowabunga, dude!
  def my_method(str)
    ret = "Nice #{str} you got there!"
    ret.upcase()
  end
end

puts MyClass.new.my_method('pizza')

will get converted to:

class MyClass {
  // Cowabunga, dude!
  myMethod(str) {
    let ret = `Nice ${str} you got there!`;
    return ret.toUpperCase()
  }
}

console.log((new MyClass).myMethod("pizza"))

Filters may be provided to add Ruby-specific or framework specific behavior. Filters are essentially macro facilities that operate on an AST (Abstract Syntax Tree) representation of the code.

Ruby2JS can be used to write backend code for execution by Node, or for the frontend in a variety of configurations including Webpack. Our installation guide will help you get set up in no time.

A note about this site: many of the examples are interactive. If you change the Ruby code above, the JavaScript code below it will be updated to match. If you open your browser’s JavaScript console, you can see the results of executing this script.

This example has been pre-configured with ECMAScript 2020 support and the functions, camelCase and return filters. Other examples may be configured differently. The Try It Online! button above will take you to a page where you can select your own configuration.

Install Now Need Help?

News Updates

React filter documentation has landed!

This filter does so much more than transpiling Ruby syntax into JavaScript. It also integrates other syntaxes and reduces the need to code repetitive boilerplate/administrativia. Sam Ruby Sam Ruby on January 6, 2021