Skip to content
Newer
Older
100644 55 lines (31 sloc) 1.16 KB
acdeb8b @joshbuddy Version bump to 0.0.0
authored Nov 20, 2009
1 =Dirge
2
7919cfb @joshbuddy deprecate dirge for callsite
authored May 31, 2010
3 ==DEPRECATED
4
5 This library is no longer maintained. Everything it does and so much more is now provided by
6 http://github.com/joshbuddy/callsite. To get back Dirge's specific functionality, you can do the following
7
8 gem install 'callsite'
9
10 And in ruby
11
12 require 'dirge'
13
14 Now everything below will work as-is!
15
acdeb8b @joshbuddy Version bump to 0.0.0
authored Nov 21, 2009
16 ==Usage
17
c448e85 @joshbuddy much simpler notation
authored Nov 20, 2009
18 require 'dirge'
acdeb8b @joshbuddy Version bump to 0.0.0
authored Nov 21, 2009
19 require_relative '../to_my_file'
0d607a2 @joshbuddy updated readme
authored Jan 24, 2010
20
c448e85 @joshbuddy much simpler notation
authored Nov 21, 2009
21 Or, the much simpler notation
22
23 require ~'../to_my_file'
acdeb8b @joshbuddy Version bump to 0.0.0
authored Nov 21, 2009
24
25 annnd.
26
27 class MyAwesomeClass
28 autoload_relative :MyConstant, 'my_awesome_class/my_constant'
29 end
30
c448e85 @joshbuddy much simpler notation
authored Nov 21, 2009
31 Again, this could be
32
33 class MyAwesomeClass
34 autoload :MyConstant, ~'my_awesome_class/my_constant'
35 end
36
acdeb8b @joshbuddy Version bump to 0.0.0
authored Nov 21, 2009
37 All of this is powered by the new function:
38
39 __DIR__
0d607a2 @joshbuddy updated readme
authored Jan 24, 2010
40
41 which takes a single line off of <tt>Kernel.caller</tt> and give you back the relative path. Calling __DIR__(caller.first) for instance, will give you the relative path to whoever called you.
42
43 There is also a more explicit, and probably, more readable version.
44
45 File.relative(path)
46
47 This will convert your path into a relative directory from wherever you are.
48
49 require_relative 'to/my/file'
50
51 and
52
53 require File.relative('to/my/file')
54
55 should be identical.
Something went wrong with that request. Please try again.