Inspired by "Getting the source directory of a Bash script from within", what's the Ruby way to do this?
Inspired by "Getting the source directory of a Bash script from within", what's the Ruby way to do this?
For newer versions of Ruby, try:
__dir__For older versions of Ruby (< 2.0), the script being run can be found using:
File.dirname(__FILE__) - relative path; orFile.expand_path(File.dirname(__FILE__)) - the absolute path.Note: Using __dir__ will return the script path even after a call to Dir.chdir; whereas, using the older syntax may not return the path to the script.
ENV["PWD"] seems the simplest way for me under Linux. I don't know of an OS-agnostic way.