joshsusser (owner)

Fork Of

Forks

Revisions

gist: 111502 Download_button fork
public
Public Clone URL: git://gist.github.com/111502.git
Embed All Files: show embed
File.here.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# require_here.rb
# by Josh Susser
 
class String
  # __FILE__.require_here 'foo' # => require 'CURRENT_DIR/foo'
  # __FILE__.require_here %w(lib foo) # joins path segments so you don't have to
  # __FILE__.require_here # add the current file's directory to the load path
  def require_here(path=nil)
    here = File.expand_path(File.dirname(self))
    if path
      require File.join(here, *path)
    else
      $LOAD_PATH.unshift(here)
    end
  end
 
  # __FILE__.require_there 'lib' # => $LOAD_PATH.unshift 'CURRENT_DIR/lib'
  def require_there(path)
    here = File.expand_path(File.dirname(self))
    there = File.join(here, *path)
    $LOAD_PATH.unshift(there)
  end
end