JRuby is a Ruby language interpreter that is written in Java. This means that it runs Ruby programs under the JVM and, therefore, runs portably anywhere that Java runs (which is nearly everywhere).
I used to think that the killer feature of JRuby was making it easier to sneak Ruby into companies via a Java back-door. But that was before I saw Charles Oliver Nutter’s JRuby presentation earlier this week at the St. Louis Gateway JUG. JRuby’s killer feature is its brilliant integration with Java code. Ruby code can call Java code (and vice versa) and Ruby classes can inherit from Java classes.
A really nice touch is that JRuby will let you call Java methods using standard Ruby conventions. This is especially nice for getters and setters, where you can take Java code that looks like this:
MyThing thing = new MyThing("blob");
thing.setName(thing.getName() + "_title");
And write it in Ruby style like this:
thing = MyThing.new("blob");
thing.name += "_title";
This also means that your Ruby code has direct access to that vast universe of Java code. Peter Cooper just wrote about his experiment using JRuby to create a cross-platform desktop GUI application using the same SWT framework that renders Eclipse. Cool stuff!


My favorite is the ability to extend the Java proxy classes with Ruby specific behaviors. For example:
# Extend a proxied class implementing the given java interface name
# by including the given Ruby module
def self.extend_proxy_with(java_interface, mod)
JavaUtilities.extend_proxy java_interface do |c|
c.include mod
end
end
Calling this method like so:
extend_proxy_with 'org.omg.uml.foundation.core.Classifier', ClassifierExtensionsModule
will mix the ClassifierExtensionsModule into any class that implements the UML Classifier interface. Of course, these extensions only work within the Ruby world, but they sure make life easier when it come to adapting some rigid Java class hierarchy for some other purpose. The program where I used this pattern was an MDA tool that works similar to Andromda but can do without the metafacade decorator layer by just extending the Java classes directly.
So not only does JRuby make it easy to use Java classes. It makes it easy to extend them at runtime as well.
thing.name += "_title"
Duh! Thanks Terry, I updated the code with your change.
Sneaking Ruby in via the JVM is certainly good, but you are right that the real benefit of JRuby is it's access to all that Java code. There's tons of "legacy" stuff out there that you can access from JRuby; code that's too gnarly to re-write. Now it's easy to hook your JRuby front-end into all that stuff. Bonus: it all gets packaged into your .jar/.war/.ear and deploys on the same old app server.
Thanks so much. Your comments help me understand what is JRuby.
@Terry: I love that feature too, but the code to do it seems to have changed in the past year. With JRuby 1.1RC1, Calling include on the block's parameter fails, but it works fine without the parameter:
def self.extend_proxy_with(java_interface, mod)
JavaUtilities.extend_proxy java_interface do
include mod
end
end
(Thanks to The jRuby Cookbook)
But you are say, that this idead is bad?,
Of course, but what do you think about that?,
I want to show you best movies:,
Try to look here and may be you find what do you want:,
Most Interested facts about that you can read here:,
Most Interested facts about that you can read here:,
I want to show you best movies:,