Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: v0.0.5
Fetching contributors…

Cannot retrieve contributors at this time

55 lines (31 sloc) 1.184 kb

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.

Jump to Line
Something went wrong with that request. Please try again.