13

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?

ylluminate
12.5k17 gold badges84 silver badges162 bronze badges
asked Jun 2, 2011 at 12:39
2
  • 6
    I'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. Commented Jun 2, 2011 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. Commented Jun 2, 2011 at 12:54

4 Answers 4

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
36.7k19 gold badges115 silver badges165 bronze badges
answered Nov 16, 2012 at 20:06
Sign up to request clarification or add additional context in comments.

Comments

3
Miguel
1,9742 gold badges18 silver badges34 bronze badges
answered Nov 6, 2011 at 15:43

Comments

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.

answered Jun 2, 2011 at 14:28

2 Comments

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
There are other examples, but few are full spec-compliant implementations of Ruby. rbv8 was last updated in 2008, for instance.
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.

answered Mar 16, 2023 at 5:08

1 Comment

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.