Minimal yet extensible Ruby to JavaScript conversion.
# Gemfile
gem 'ruby2js'Or install directly:
gem install ruby2jsRuby2JS 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 # }require 'ruby2js'
puts Ruby2JS.convert("a = {age: 3}; a.age += 1", preset: true)
# => let a = {age: 3}; a.age++ruby2js --preset file.rb
echo "puts 'hello'" | ruby2js --preset- Filters - Transform Ruby methods to JavaScript equivalents (e.g.,
.each→.forEach) - ES Level Support - Target specific JavaScript versions (ES5 through ES2022+)
- Framework Integrations - Rails, Stimulus, React, Lit, and more
- Live Demo - Try it in your browser (runs entirely client-side via Opal)
bundle install
bundle exec rake test_allThe 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 serverThe site will be available at http://localhost:4000.
- Update the version in both
packages/ruby2js/package.jsonandlib/ruby2js/version, ensuring they match. - Run
bundle exec rake release_core
MIT License - Copyright (c) 2009, 2025 Macario Ortega, Sam Ruby, Jared White
See LICENSE for details.