I have a Ruby script with path /foo/bar/gazook/script.rb
. I also created a symlink to it in $HOME/bin
.
Now, I want my Ruby script to access some other file in directory /foo
, and to keep paths relative, I have a variable FOO_DIRECTORY = File.expand_path(File.dirname(__FILE__) + "/../../")
in my script.
The problem is that if I run my script from its symlink, this relative directory is wrong (since I guess its expanding from a different location).
How do I fix this? Is there a way besides using an absolute path?
bin
may be a symlink, too. I'd recommendFile.realpath
. – Hypodermis