How to get the directory of the current script?

Hi,

How do I get the directory path of the file that is currently
executing?

Also, if I have a module, within a function, how do I get the parent
directory (full path) of that module?

Thanks

Javi

I’ve never done it so I don’t know for sure, but I’ve seen lines like

RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)

so I’m guessing there’s a way to use FILE to get the full path similar to getting the directory name.

You should be able to use the Dir class.


Dir.pwd

http://ruby-doc.org/core/classes/Dir.html