Dirge¶ ↑
DEPRECATED¶ ↑
This library is no longer maintained. Everything it does and so much more is now provided by github.com/joshbuddy/callsite. To get back Dirge’s specific functionality, you can do the following
gem install 'callsite'
And in ruby
require 'dirge'
Now everything below will work as-is!
Usage¶ ↑
require 'dirge' require_relative '../to_my_file'
Or, the much simpler notation
require ~'../to_my_file'
annnd.
class MyAwesomeClass autoload_relative :MyConstant, 'my_awesome_class/my_constant' end
Again, this could be
class MyAwesomeClass autoload :MyConstant, ~'my_awesome_class/my_constant' end
All of this is powered by the new function:
__DIR__
which takes a single line off of Kernel.caller
and give you back the relative path. Calling __DIR__(caller.first) for instance, will give you the relative path to whoever called you.
There is also a more explicit, and probably, more readable version.
File.relative(path)
This will convert your path into a relative directory from wherever you are.
require_relative 'to/my/file'
and
require File.relative('to/my/file')
should be identical.