views:

79

answers:

2

Hello, everyone!

Inspired by this question, what's the Ruby way to do this?

+11  A: 

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.

ba
+1  A: 

ENV["PWD"] seems the simplest way for me under Linux. I don't know of an OS-agnostic way.

Shadowfirebird
Thanks! Good for my Linux-specific general knowledge.
java.is.for.desktop
That's the home directory, not the current working directory or the directory where the script is located.
Matthew Flaschen
B*gger, lack of sleep will do that. I meant ENV["PWD"] of course. But ba's answer is way better.
Shadowfirebird
Please edit the answer then!
java.is.for.desktop
Isn't that simply the working directory of the process? I thought that the OP wanted the directory containing the script.
D.Shawley
No, the process could execute an external script from elsewhere.
java.is.for.desktop
Or `Dir.pwd` to get the current working directory...
kejadlen