百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
R

ruby2js

> 编程语言
开源

Ruby 到 JavaScript 转换

491 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

Ruby 到 JavaScript 转换

Ruby2JS

Minimal yet extensible Ruby to JavaScript conversion. Documentation | Live Demo

Installation

ruby
# Gemfile
gem 'ruby2js'

Or install directly:

bash
gem install ruby2js

Examples

Ruby2JS converts Ruby syntax to clean, readable JavaScript:

ruby
# 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++

Command Line

bash
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)

Demos

  • Opal Demo - Full-featured demo using Opal (~5MB)
  • Selfhost Demo - Lightweight demo using transpiled Ruby2JS (~200KB + Prism WASM)
  • Ruby2JS-on-Rails - Rails-like blog app running entirely in JavaScript

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.

Contributing

Running Tests

bash
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:

bash
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.

Issues· 26 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rubyjavascriptruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言