Skip to content

Instantly share code, notes, and snippets.

@jclosure
Created January 18, 2013 03:32
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 jclosure/4562138 to your computer and use it in GitHub Desktop.
Save jclosure/4562138 to your computer and use it in GitHub Desktop.
How to set the directory context to the same dir or nearby dir of currently executing Ruby script
#place at top of file
$:.unshift(File.dirname(__FILE__))
#this will include the dir context to the same folder as the currently executing script
-
|-examples
|-example1.rb
|-lib
|-library1.rb
#with this structure and the code, you can do:
$:.unshift(File.dirname(__FILE__) + "/../lib")
#the case shown here is excellent for say having a gem with an examples directory and you want to set the dir context to the lib dir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment