java.is.for.desktop java.is.for.desktop - 3 months ago 8
Ruby Question

Can a Ruby script tell what directory it’s in?

Inspired by "Can a Bash script tell which directory it is stored in?", what's the Ruby way to do this?

Answer

File.dirname(__FILE__) will give you the path relative to the script being run. File.expand_path(File.dirname(__FILE__)) will give you the absolute path.