Skip to content
Torsten Rüger edited this page Jan 11, 2018 · 3 revisions

Welcome to the ruby2js wiki!

Ruby2JS transforms ruby to javascript. It let's you write ruby syntax, and get javascript semantics. Basically it avoids the mental switch for the rubyist.

Ruby2JS is very modular, it can be used in Sinatra or Rails, with tilt or haml.

Also you can choose which transformation you want to apply to your ruby. The functionality is modularized into filters, and you can require the ones you want. There are basic filters that apply to any js, but many are meant to make working with external js libraries easier, ie react, vue, underscore etc.

Below is a list of filters and integrations (currently incomplete):

Basic

The functions filter see the readme is what transforms ruby methods into js functions. Classes map to prototypes. Blocks can be used and transform to anonymous functions, and a whole lot of ruby method names get rewritten to their js equivalents.

There is also a return filter, that inserts ruby style automatic returns for the last statement. And a require filter that inlines the required file at compile time.

More js specific there is are strict and es2015 filters, that turn those features on in the output.

A wiki page on Iterating explains common enumerable conversions, and how to create for loops.

Vue

The Vue filter lets you write vue methods as methods on a class. Instance variables of the class become vue data, class variables become vue props, and methods without arguments become computed properties, while methods with arguments become vue methods.

The filter also lets you write wunderbar style render functions and automatically detects if you are writing a component or app.

Angular

React

Underscore

Rubyjs

jQuery

Minitest