Here's my first little attempt at Ruby metaprogramming. It's an 
extension of ActiveRecord::Base to allow for preloading reference data that does not change (at least not while the app is running)

<pre>
<code>
module ActiveRecord
  class Base
    def self.preload
      cattr_reader :all
      class_eval("@@all = self.find(:all)")
    end
  end
end
</code>
</pre>

In order for the above code to take any effect, it needs to be loaded. Stick it into a file and @require@ that file at the end of @config/environment.rb@. Alternatively, use the more general mechanism shown in OverridingRailsMessagesInAnotherLanguage.

<pre>
<code>
class Something < ActiveRecord::Base
  preload
end
</code>
</pre>

Then, in a controller, say, you can access the preloaded instances as 
<pre>
<code>
Something.all().
</code>
</pre>

Note that in "development mode", i.e., when @load@ is used, not @require@, the records are still loaded each time their class is loaded. That's as it should be. In "production mode" classes are loaded just once, thus records are preloaded once, too.

--MichaelSchuerig
