Interesting Things
- Running initialization blocks per environment
- Set an array in
environment.rbto capture your procs that will do your post-initialization:POST_LOAD_BLOCKS = [] - Now, in your environment-specific initialization files, you can do stuff like:
- Then, back in
environment.rb, after your environment has been initialized, loop over your array:
- Set an array in
<code>
POST_LOAD_BLOCKS << Proc.new {
a.runFoo
b.runBar
}
</code>Paydirt! These procs you’re appending to the POST_LOAD_BLOCKS array will get executed after your environment is completely initialized.
- Use
silence_warningsto (you guessed it!) ‘silence’ warnings in Ruby – only pros should use it, and only when its clear exactly what you are doing!
Ask for Help
- None need today
Rails::Initializer has a method named after_initialize that takes a block. Unfortunately, it can only take one callback, so it can’t be used multiple times without special handling.
December 12, 2007 at 11:50 pm