Neal Gafter blogs about adding closures to java. Which Ruby (or any other language) features would you like to add to the Java language. Or do you think it is possible to create a Framework with the power and flexibility of Rails with Java without any changes?
Personally, I'd much rather we just started using jRuby for all of our programming on the JVM. As Stuart would say were he online right now, in a perfect world, we'd write code in jRuby and Java itself would become the Assembler (and not the COBOL) of our generation.
Put a gun to my head, and I'd say:
Regular expressions as first-class entities
Closures (and related items like enumeration support that makes use of them)
JRuby and Groovy have a family resemblance, but they are distant relations. The last time I looked Groovy code still gets "hardened" into Java classes. JRuby code, on the other hand, follows the Ruby way of being "the glue that never sets." JRuby code can dynamically modify the behavior of other JRuby code. The subtle danger is that JRuby and Groovy are similar for about the first 50% of what makes Ruby cool. For the latter half, only JRuby delivers the goods.
So, let's say you have a class that's buried somewhere, like, Rails' ActionController. And you want to add a new method to it, like, "help" (so that all your controllers had a /your_controller/help url that tells what that controller is for).
You can create a module to hold the new, shared method:
Then, you can, from anywhere in the code, call:
Voila. Your controller now has a "help" method.
What if you wanted to wrap a method already in a class? For that, you would use .
If you then extend that into a class with a "save" method, it renames the original method, creates a new method of the same name (a proxy, if you will), and when it is called, the new method logs the process and forwards the call to the original method.
There is a new addition to Rails 1.2 called alias_method_chain which makes the whole process a little cleaner, as well. [ January 31, 2007: Message edited by: Justin Gehtland ]