Ruby require secret

22 Jan 2013

It's always annoying that, when you want to require some file, you have to:

require File.expand_path('../../something', __FILE__)

And if `something.rb` requires something else in its own path, it will be even more annoying.

The secret is to add `../../` as a default path. Here is how you can do it:

$:.push(File.expand_path('../../', __FILE__))

And now you can just `require 'something'`

Give it a kudos