How can I compile Ruby to Javascript? [closed]

◇◆丶佛笑我妖孽 提交于 2019-12-03 14:54:54

问题


I'm working on a piece of logic that I would like to express on the server as well as in the browser. Something like validating a form where there must be certain logical relationships between the elements based on what has already been entered.

So... If I can write the logic once and somehow end up with both Ruby and with Javascript, I can write the logic just once and not have to worry about making sure that two pieces of code written in different languages have the same functional behaviour.

I don't need to reproduce everything in Ruby, obviously, and one simplification might be to port a single general-purpose library like Functional Javascript to Ruby.

Does anyone have experience with RubyJS? Can anyone point me to an existing project using RubyJS? Thanks in advance...


回答1:


As far as I can tell, Opal is the best Ruby to JS converter/compiler out there right now. Here you can see it in action.

It isn't perfect, but it works most of the time and unlike older projects such as RubyJS, Opal is still being actively developed.




回答2:


I know about http://hotruby.yukoba.jp/ but have never used it




回答3:


maybe this helps: http://opalrb.org/ haven't tried it though




回答4:


I recently heard about a project named "Johnson" which embeds the Spidermonkey JavaScript interpreter inside Ruby. http://github.com/jbarnette/johnson

You could then eval some javascript inside ruby.



来源:https://stackoverflow.com/questions/2144169/how-can-i-compile-ruby-to-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!