require File.dirname(FILE) seems like an incredibly common idiom.
boy is it ugly! Ruby is a beautiful language so why should we litter it
with ugly statements like that?
Now you don’t have to! At the suggestion of Roger P. I’ve added a new
feature to the require_all gem. Introducing require_rel. Here’s how it
works… let’s start with an ugly require statement:
require File.dirname(FILE) + ‘foobar’
Yeech. Can we do better? Yes we can:
Done! The require_rel statement works relative to the directory the
is located in. Bye bye File.dirname(FILE)!
Even better, require_rel has the same code loading powers as
If ‘foobar’ is a directory, it will look for all the .rb files under the
foobar directory and use require_all’s automagic dependency resolution
load them in the proper order. (In case anyone is wondering, if you
‘foobar’ directory and a ‘foobar.rb’ require_all will prefer the
over the .rb file). Or you can give require_rel a custom glob which
relative to the current file.
If you’d like to learn more, check it out on github: