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?

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)

Sign up to request clarification or add additional context in comments.

Comments

3

List of languages that compile to JS...

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.

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.

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

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.