如何将Ruby编译为Javascript? [英] How can I compile Ruby to Javascript?

查看:122
本文介绍了如何将Ruby编译为Javascript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一段我想在服务器以及浏览器中表达的逻辑。例如验证一个表单,其中基于已经输入的内容必须有某些逻辑关系。

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.

所以...如果我可以写逻辑一次,不管怎样,最终与Ruby和JavaScript,我可以写逻辑只是一次,而不必担心确保用不同语言编写的两段代码具有相同的功能行为。

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.

我不需要重现Ruby中的一切,显然,一个简化可能是端口一个通用库,如功能Javascript 到Ruby。

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.

有没有人有RubyJS的经验?任何人都可以指向我使用RubyJS的现有项目?
提前感谢...

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

推荐答案

据我所知, Opal 是目前最好的Ruby到JS转换器/编译器。 在这里你可以看到它在行动。

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.

这不是完美的,但它的工作大部分时间,项目,如 RubyJS ,Opal仍在积极开发中。

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

这篇关于如何将Ruby编译为Javascript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆