Ruby 到 JavaScript 转换
Minimal yet extensible Ruby to JavaScript conversion. Documentation | Live Demo
# 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 let a = {age: 3}; a.age++ruby2js --preset file.rb
echo "puts 'hello'" | ruby2js --preset.each → .forEach)The selfhost demo runs Ruby2JS transpiled to JavaScript, demonstrating that Ruby2JS can convert itself. The Ruby2JS-on-Rails demo shows a complete Rails-style MVC application with ActiveRecord, controllers, and ERB views running in the browser or on Node.js/Bun/Deno.
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.
packages/ruby2js/package.json and lib/ruby2js/version, ensuring they match.bundle exec rake release_coreMIT License - Copyright (c) 2009, 2025 Macario Ortega, Sam Ruby, Jared White
See LICENSE for details.
暂无开放 Issues,或尚未同步最近议题。