CodeSmith CodeSmith - 3 months ago 9
Ruby Question

How to find the full path that was used to run a Ruby script

I have a script ("foo") that gets installed as an executable command on the path. I can invoke

foo
on the commandline to get the currently installed version.

But sometimes I like to run a development version by running
path/to/script/home/foo
.

Is there a way that I can tell if
foo
was invoked by calling
foo
or if it was called using the full path?

Answer

You can access that value as $0 inside your script.