Class: ThisFile

Inherits:
Object
  • Object
show all
Defined in:
lib/thisfile.rb

Overview

Easy to use file relative paths.

( ThisFile / "foo.rb" ).should == File.expand_path("../foo,rb", __FILE__ )

Class Method Summary collapse

Class Method Details

./(path) ⇒ Object



28
29
30
# File 'lib/thisfile.rb', line 28

def self./ (path)
  File.expand_path( path, File.dirname(ThisFile.__file__(2)))
end

.__file__(n = 0) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/thisfile.rb', line 16

def self.__file__(n=0)
  begin
    raise "foo"
  rescue Exception => e
    parse_backtrace(e.backtrace)[n]
  end
end

.expand_path(path) ⇒ Object



24
25
26
# File 'lib/thisfile.rb', line 24

def self.expand_path( path )
  File.expand_path( path, File.dirname(ThisFile.__file__(2)))
end