Ruby 和 JRuby 有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1728999/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What's the difference between Ruby and JRuby?
提问by Ash
Can anyone please provide me in layman's terms the difference between developing a JRuby and a Ruby, Rails application?
任何人都可以用外行的话告诉我开发 JRuby 和 Ruby、Rails 应用程序之间的区别吗?
I use NetBeans as my Ruby on Rails IDE and every-time I create a project is asks me that question - and I don't really get the difference. Are there any pro and cons?
我使用 NetBeans 作为我的 Ruby on Rails IDE,每次我创建一个项目时都会问我这个问题 - 我并没有真正明白其中的区别。有什么优点和缺点吗?
回答by danivovich
Ruby runs within a native C based interpreter. JRuby runs inside the Java Virtual Machine. There are many gems and plugins that might not work inside JRuby, specifically one's with native C extensions, unless they've been rewritten to run in Java.
Ruby 在基于 C 的本地解释器中运行。JRuby 在 Java 虚拟机中运行。有许多 gem 和插件可能无法在 JRuby 中工作,特别是那些带有原生 C 扩展的 gem,除非它们被重写为在 Java 中运行。
Ultimately the difference comes in when you want to actually deploy your application (assuming the gems you want to use weren't an issue). If you would like to deploy to a java web server, then JRuby would be the way to go. If you have a *nix environment, then Passenger + Nginx or Apache is very popular as well, which uses the standard ruby or ruby enterprise interpreter. There is always the mongrel or thin cluster option as well, again using the standard interpreter.
最终,当您想要实际部署您的应用程序时(假设您想要使用的 gem 不是问题),差异就会出现。如果您想部署到 Java Web 服务器,那么 JRuby 将是您的最佳选择。如果您有*nix 环境,那么Passenger + Nginx 或Apache 也很受欢迎,它们使用标准的ruby 或ruby 企业解释器。总是有 mongrel 或 Thin cluster 选项,同样使用标准解释器。
回答by Tamas Mezei
JRuby runs on the Java VM (the interpreter was written in Java), while the original Ruby interpreter was written in C. Both have up- and downsides also (Ruby can use native extensions, JRuby can access to Java types, objects etc.)
JRuby 在 Java VM 上运行(解释器是用 Java 编写的),而原始的 Ruby 解释器是用 C 编写的。两者都有优缺点(Ruby 可以使用本机扩展,JRuby 可以访问 Java 类型、对象等)
JRuby uses Ruby 1.8.6's syntax, 1.9.x will be available soon. JRuby has Java threads (meaning it will scale to many cpus, cores etc.), Ruby has some issues with userspace threading, locking ec.
JRuby 使用 Ruby 1.8.6 的语法,1.9.x 即将推出。JRuby 有 Java 线程(意味着它将扩展到许多 CPU、内核等),Ruby 在用户空间线程、锁定 ec 方面存在一些问题。
Personally, I use JRuby with Glassfish v3 and Netbeans for RoR development, it scales a lot better than ruby + loads of mongrels, Apaches and it's easier to manage.
就我个人而言,我将 JRuby 与 Glassfish v3 和 Netbeans 一起用于 RoR 开发,它的扩展性比 ruby + 大量杂种、Apache 好得多,并且更易于管理。
回答by Thomas Jung
JRuby is mostly Ruby compatible. One aspect of JRuby is that you can run it in non-compatiblemodes for performance reasons.
JRuby 主要与 Ruby 兼容。JRuby 的一个方面是,出于性能原因,您可以在非兼容模式下运行它。
回答by J?rg W Mittag
Ruby is a programming language. JRuby is an implementation of the Ruby programming language.
Ruby 是一种编程语言。JRuby 是 Ruby 编程语言的实现。
Asking about the difference between the two doesn't really make sense: they are on two entirely different levels of abstraction.
询问两者之间的区别并没有什么意义:它们处于两个完全不同的抽象级别。
It's similar to asking what is the difference between a car and a Prius. It doesn't make sense, either: a Prius an implementation of the general concept of a car. You could ask what's the difference between a Prius and a Hummer or the difference between a car and an aeroplane, but the difference between a car and a Prius doesn't make sense.
这类似于询问汽车和普锐斯有什么区别。这也没有任何意义:普锐斯是汽车一般概念的实现。你可能会问普锐斯和悍马有什么区别,或者汽车和飞机有什么区别,但汽车和普锐斯之间的区别没有意义。
Similarly, with Ruby, you could ask about the difference between Ruby and Python or JRuby and MRI, but the difference between Ruby and JRuby doesn't make sense.
同样,对于 Ruby,您可以询问 Ruby 和 Python 或 JRuby 和 MRI 之间的区别,但 Ruby 和 JRuby 之间的区别没有意义。
回答by Brian Agnew
回答by RushabhM
JRuby is a java implementation of Ruby interpreter. Rails (aka Ruby on Rails) is a web application framework written in Ruby. This article explains how Ruby code is actually executed through JVM http://patshaughnessy.net/2012/2/7/journey-to-the-center-of-jruby
JRuby 是 Ruby 解释器的 Java 实现。Rails(又名 Ruby on Rails)是一个用 Ruby 编写的 Web 应用程序框架。这篇文章解释了 Ruby 代码是如何通过 JVM 实际执行的http://patshaughnessy.net/2012/2/7/journey-to-the-center-of-jruby
回答by ennuikiller
As far as I know jruby is simply a ruby implementation written in java so it allows easy integration with the java runtime.
据我所知,jruby 只是一个用 java 编写的 ruby 实现,因此它可以轻松地与 java 运行时集成。
回答by ennuikiller
JRuby is a Java implementation of the Ruby programming language.
JRuby 是 Ruby 编程语言的 Java 实现。

