Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Ruby to JavaScript conversion

License

NotificationsYou must be signed in to change notification settings

ruby2js/ruby2js

Repository files navigation

Minimal yet extensible Ruby to JavaScript conversion.

Gem VersionCI

Documentation |Live Demo

Installation

# Gemfilegem'ruby2js'

Or install directly:

gem install ruby2js

Examples

Ruby2JS converts Ruby syntax to clean, readable #"auto" data-snippet-clipboard-copy-content="# Ruby # JavaScripta = { 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 # }">

# Ruby                              # JavaScripta={age:3}# let a = {age: 3}a.age +=1# a.age++items.map{ |x|x *2}# items.map(x => x * 2)classDog <Animal# class Dog extends Animal {defbark#   bark() {puts"woof!"#     console.log("woof!")end#   }end# }

Quick Start

require'ruby2js'putsRuby2JS.convert("a = {age: 3}; a.age += 1",preset:true)# => let a = {age: 3}; a.age++

Command Line

ruby2js --preset file.rbecho"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 installbundleexec rake test_all

Running the Website Locally

Theruby2js.com website (including the live demo) can be run locally from thedocs folder:

cd docsbundle installyarn installbundleexec rake# build demo assets (Opal-compiled ruby2js, etc.)bin/bridgetown start# run the site's dev server

The site will be available athttp://localhost:4000.

Release Process for Maintainers

  1. Update the version in bothpackages/ruby2js/package.json andlib/ruby2js/version, ensuring they match.
  2. Runbundle exec rake release_core

License

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

SeeLICENSE for details.

About

Ruby to JavaScript conversion

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp