Skip to content

Instantly share code, notes, and snippets.

@pivotal-legacy
Forked from joshsusser/File.here.rb
Created May 14, 2009 06:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pivotal-legacy/111532 to your computer and use it in GitHub Desktop.
Save pivotal-legacy/111532 to your computer and use it in GitHub Desktop.
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment