Useless (but nifty) Ruby code

Here's a nifty little piece of useless Ruby code:

and the result is:

require "quine"
this.that.and.something_else

Named instances for ActiveRecord

For a project that I'm working on at my day job, we have a governmental client for which we are building a pretty large and complicated online/offline Ruby on Rails application. As part of this app there are tons of data-specific rules. For example, if a client with HIV is being assessed then certain fields may have to be displayed/hidden and there are rules that get applied differently. So lets say you have the following setup:

Now, somewhere in your code you want to be able to do take a specific action only if that client has a particular diagnosis. Without named_instances you might do something like:

With named_instances you can do the following faster and more concise code:

We've been using this functionality for about 6 months now and its been great. The gem is out on GemCutter (which rocks) and the repo is at GitHub. Hopefully it will be useful in your projects. Comments, criticisms, and patches welcome.

Weirdest test failure ever...

So based on some customer feedback on a project I'm currently working on, I added a validation requiring that one of the dates be in the past. The validation is pretty straightforward:

After re-running the test suite though, I got a couple of failures. After digging into the code, it turns out that the following code snippit evaluates to true!

Of course this makes no sense. What's more is that I tried the code again while writing this blog post and now its false. So I did some digging into the Ruby internals and it turns out that Time#< is implemented in C in the following method:

The best I can come up with is that there's an problem with the GetTimeval method since its just a macro that pulls out some data from a time struct -- but the Date class is implemented in pure Ruby. Anyone come across this or can explain better?