Require_all 1.1.0: the final nail on the coffin of require File.dirname(__FILE__)

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:

require_rel ‘foobar’

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
have a
‘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:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs