Sunday, May 13, 2007

Reloading Ruby Classes in Rails

I ran across a bug in Date::Format today, and after spending a few hours hacking away at a fix (the date/format.rb code is *uuuuugly* and *sloooow*...someone should really rewrite that. Better yet, rewrite it in C), I thought I'd submit a patch. So I grabbed the ruby_1_8 branch and lo and behold, my issue had already been fixed!

So the question now was how to monkeypatch the entire Date::Format module? Simply require-ing it as a plugin doesn't work, since Date::Format is already loaded at that point. The trick then is to use load instead of require.

First, I tried this:


load 'date/format.rb'


(note: load needs the actual filename; it doesn't have the magic that require does) but that gave me an error:


in `load': wrong number of arguments (1 for 0) (ArgumentError)


Turns out Rails::Plugin::Loader defines its own load, so:


Kernel::load 'date/format.rb'


et voila!

Stop iPhoto from Launching when you Connect your Camera

It took me a bit of digging to find this, so I thought I may as well spread the word here. I've started using Adobe Lightroom for managing my photos, but every time I connect my camera or card reader to import photos, iPhoto would launch, and I couldn't figure out where I could change that. I finally discovered that the setting is in the Image Capture application. Run that, then go to Preferences and you'll find it there. Why they wouldn't also put it in iPhoto, Lightroom, or even on a preferences panel is beyond me.