# Require\_all 1.1.0: the final nail on the coffin of require File.dirname(\_\_FILE\_\_)

**URL:** <https://www.ruby-forum.com/t/require-all-1-1-0-the-final-nail-on-the-coffin-of-require-file-dirname-file/172308>\
**Category:** Ruby\
**Created:** [July 19, 2009, 3:04am UTC](https://www.ruby-forum.com/t/require-all-1-1-0-the-final-nail-on-the-coffin-of-require-file-dirname-file/172308 "2009-07-19T03:04:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![murfhy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d26b3c/32.png) [@murfhy](https://www.ruby-forum.com/u/murfhy)\
**Post date:** [July 19, 2009, 3:04am UTC](https://www.ruby-forum.com/t/require-all-1-1-0-the-final-nail-on-the-coffin-of-require-file-dirname-file/172308/1 "2009-07-19T03:04:13Z")

</div>

require File.dirname( **FILE** ) seems like an incredibly common idiom.  
But  
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  
caller  
is located in. Bye bye File.dirname( **FILE** )!

Even better, require\_rel has the same code loading powers as  
require\_all.  
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  
to  
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  
directory  
over the .rb file). Or you can give require\_rel a custom glob which  
works  
relative to the current file.

If you’d like to learn more, check it out on github:

[http://github.com/tarcieri/require\_all/tree/master](http://github.com/tarcieri/require_all/tree/master)
