Project

ruby2js

0.13
No release in over a year
The base package maps Ruby syntax to JavaScript semantics. Filters may be provided to add Ruby-specific or framework specific behavior.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Runtime

 Project Readme

Ruby2JS

Minimal yet extensible Ruby to JavaScript conversion.

Gem Version CI

Documentation | Live Demo

Installation

# Gemfile
gem 'ruby2js'

Or install directly:

gem install ruby2js

Examples

Ruby2JS converts Ruby syntax to clean, readable JavaScript:

# Ruby                              # JavaScript
a = { age: 3 }                      # let a = {age: 3}
a.age += 1                          # a.age++

items.map { |x| x * 2 }             # items.map(x => x * 2)

class Dog < Animal                  # class Dog extends Animal {
  def bark                          #   bark() {
    puts "woof!"                    #     console.log("woof!")
  end                               #   }
end                                 # }

Quick Start

require 'ruby2js'

puts Ruby2JS.convert("a = {age: 3}; a.age += 1", preset: true)
# => let a = {age: 3}; a.age++

Command Line

ruby2js --preset file.rb
echo "puts 'hello'" | ruby2js --preset

Features

  • Filters - Transform Ruby methods to JavaScript equivalents (e.g., .each.forEach)
  • ES Level Support - Target specific JavaScript versions (ES2020 through ES2025)
  • Framework Integrations - Rails, Stimulus, React, Lit, and more
  • Live Demo - Try it in your browser (runs entirely client-side via Opal)

Contributing

Running Tests

bundle install
bundle exec rake test_all

Running the Website Locally

The ruby2js.com website (including the live demo) can be run locally from the docs folder:

cd docs
bundle install
yarn install
bundle exec rake            # build demo assets (Opal-compiled ruby2js, etc.)
bin/bridgetown start        # run the site's dev server

The site will be available at http://localhost:4000.

Release Process for Maintainers

  1. Update the version in both packages/ruby2js/package.json and lib/ruby2js/version, ensuring they match.
  2. Run bundle exec rake release_core

License

MIT License - Copyright (c) 2009, 2025 Macario Ortega, Sam Ruby, Jared White

See LICENSE for details.