Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between Ruby and JRuby? [closed]

Can anyone please provide me in layman's terms the difference between developing a JRuby and a Ruby, Rails application?

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?

like image 241
Ash Avatar asked Nov 13 '09 12:11

Ash


People also ask

What is the difference between Ruby and JRuby?

JRuby is similar to the standard Ruby interpreter except written in Java. JRuby features some of the same concepts, including object-oriented programming, and dynamic typing as Ruby. The key difference is that JRuby is tightly integrated with Java, and can be called directly from Java programs.

What does JRuby do?

JRuby is an open source implementation of the Ruby programming language for the Java Virtual Machine (JVM). It allows Ruby applications to be run within a Java Virtual Machine and interface with libraries written in either Java or Ruby.

Should I use JRuby?

If you are using an application that will stay alive for long, and you want better runtime support, JRuby can be a great way to go. Otherwise, you can safely wait until you need these things to actually make the move (it is likely to go smoothly). Excellent answer, that's exactly what I needed to know.

Is JRuby fast?

The JVM makes different performance trade-offs than MRI Ruby. Notably, an untuned JVM process has a slow start-up time, and with JRuby, this can get even worse as lots of standard library code is loaded on start-up.


2 Answers

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.

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.

like image 108
danivovich Avatar answered Oct 08 '22 21:10

danivovich


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

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.

like image 35
Tamas Mezei Avatar answered Oct 08 '22 20:10

Tamas Mezei