Opal: Ruby to Javascript

426 Views Asked by At

I learned about Opal for Ruby recently and would like to convert a Ruby file to Javascript. I've used Coffeescript before, and I can compile a Coffeescript file to Javascript with a certain command on Node.js. How do I do the same with Ruby and Opal to Javascript ?

1

There are 1 best solutions below

0
On

To compile your Ruby to JavaScript:

opal -c program.rb > program.js

-c means "compile to JavaScript" (as opposed to "execute now"); the JavaScript is written to the standard output, so you can use redirection to capture it to a file.