Is it possible to convert Ruby code to Javascript at all? I have heard of RubyJS but this appears to not work with Ruby 1.9.2 - is this the case?
Asked
Active
Viewed 9,304 times
13
-
6I'd always be cautious of writing code in one high-level language and then converting to another. Like all code generators, it's unlikely to end up with the best possible code in the target language to do the job. It's almost always better to simply write the javascript code directly. – Spudley Jun 02 '11 at 12:47
-
Also, you have to consider if the library that your Ruby code uses can be translated directly to JavaScript. More likely, you'll be porting your Ruby code to JavaScript. – OnesimusUnbound Jun 02 '11 at 12:54
4 Answers
11
It seems to me that Opal is the best Ruby to JavaScript converter/compiler out there right now. You can see it in action here.
It isn't perfect, but it works in most cases and unlike older projects such as RubyJS, Opal is still being actively developed. (Check out Opal on Github)

ivan_pozdeev
- 33,874
- 19
- 107
- 152

Ajedi32
- 45,670
- 22
- 127
- 172
2
There are many efforts that have tried to do this, but most have only been to an academic degree. For instance, this Ruby 1.9.2 VM in JavaScript.
Most efforts to port to JavaScript focus on the Google V8 engine and not necessarily the browser-side equivalent.

tadman
- 208,517
- 23
- 234
- 262
-
where can i find this stuff? i have some ruby code i want to run in node.js and i dont want to rewrite all the ruby – Carter Cole Jul 18 '11 at 23:57
-
1There are other examples, but few are full spec-compliant implementations of Ruby. [rbv8](https://github.com/macournoyer/rbv8) was last updated in 2008, for instance. – tadman Jul 19 '11 at 14:27
0
Try https://www.ruby2js.com/demo?preset=true Worked fine for me. In case you're using very long scripts and it fails, try smaller chunks of code.

Mayank Goyal
- 1
- 2
-
1Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 21 '23 at 09:53