A Ruby pre-defined variable and you. (and JRuby)


I was recently wrestling with an obscure JDBC bug in Sequel. I was seeing an error connecting to the PostgreSQL database but it was being rescued by the Sequel JDBC adapter and hidden a little bit. (If you’re curious to see the fix it’s over on Github). Anyway, the original error led me to believe that the JDBC adapter for postgres wasn’t being loaded at all.

What to do?

What else? Get on the #jruby IRC channel on Freenode. Seriously, when you’re running JRuby and you come across a problem you go to there. Charles, Nick, and Tom (JRuby core) are always lurking around and very willing to help. Charles told me to look at $” and see what was loaded.


A magic-pre-defined variable in Ruby (and JRuby) – see what I did there with the title? According to zenspider’s QuickRef:

$" The array contains the module names loaded by require.

Huh. Okay, cool. As a bonus JRuby throws the loaded jars in there as well. ( I really should learn all of these, come to think it, so should you. )

So what

You take a look at that array and you’ll see all of the modules names currently loaded. Good stuff. Here is the part from the project that helped me resolve my issue:


I was able to see that the postgresql jar was loaded along with the supporting cast of characters. This led me to the #sequel IRC channel where Jeremy Evans and I were able to figure this little guy out. Trying to troubleshoot a potential jar loading problem in JRuby? $” is your friend. (and so is IRC it seems!)