PPL 30 Day 6: JRuby

This is part of the Peer Pressure Learning 30 series. To learn more about what in the hell that means, see the intro to the series, A Good Time To Learn.

Shameful admission: I have managed to last to now without trying any Ruby beyond MRI (and Ruby Enterprise Edition, if you can count that as a separate Ruby). That’s pathetic, I know. So, I’ll finally be diving into JRuby today. JRuby is, of course, Ruby on the JVM, for those who have been living under a larger rock than the one I’ve been inhabiting.

(By the way, doesn’t ‘Ruby on the JVM’ qualify JRuby for the status of More Enterprisey than Ruby Enterprise Edition. I mean, I realize REE is a tongue-in-cheek name anyway, but I think we as community should discuss this further. Perhaps we could just have a mirror of JRuby that we refer to as Enterprise Ruby to further adoption in those scary, tie-required places. Nevermind. That’s an awful idea.)

Installation

Seriously, the rock I was under was a pretty large one. I installed RVM (Ruby Version Manager) for the first time. Consequently, installing JRuby was pretty easy:

rvn install jruby

What did people do before RVM? (That’s rhetorical, by the way.)

Resources

JRuby Wiki

The JRuby Wiki contains a large amount of information, as well as a large number of links to other resources – blog posts, articles, etc. It also seems to be the most up-to-date reference point, though it does point to some no-longer-available articles.

I think the most interesting tutorial-like resource I came across was Calling Java From Ruby in the wiki. Creating a frame and adding a label to it, though completely trivial, was a mild thrill for me. (Man, that rock I was under was big.)

Overall, I found it a bit difficult to find interesting reads about JRuby, and evidently most JRuby articles were written in 2007. Perhaps I wasn’t looking in the right places.

What I Think I Now Know

It’s surprising the number of Ruby gems that one uses frequently that require native extensions (in other words, they aren’t pure Ruby). JRuby doesn’t support buiding native C libraries, of course. Either the gem needs to provide a Java equivalent, or you need to find another library. This killed my plans when I wanted to play with the otherwise super-simple vimtweets.com code. I require Nunemaker’s Twitter gem, which requires some native C library. (It requires yajl-ruby for streaming JSON parsing.) Well, it just wounded my plans, and not fatally (that came later). I decided the twitter gem isn’t important enough to the project to let it ruin Day 6.

So, I decided to use a basic httperf test to see how JRuby compared to my system’s Ruby. Well, at least, that’s what I wanted to do. Unfortunately, even after running:

gem install activerecord-jdbcpostgresql-adapter

… the simple Rails app couldn’t connect to the database. I’m confident I can solve the problem, but not today. The Postgresql adapter landed the fatal blow, with some help from Time. So, Day 6 feels like a failure. Though I think you typically learn more from failing than from succeeding, that doesn’t make it feel any better.

I think the ability to use Java classes from within Ruby is a pretty powerful feature, though it makes me a cringe. I intend to keep abreast of JRuby happenings, and use JRuby more often, to keep my knowledge and skills sharp in anticipation of the opportunity to push Ruby into other parts of the development at my current employer. That, and because I simply should.


While I’m in this frame of mind, I’d like to dive into Ruby 1.9.2. Plus, it’s about time some plugins and gems I’ve written get certified as compatible, right? So, tomorrow is Ruby 1.9.2.