George Jempty George Jempty - 2 months ago 9
Ruby Question

how to get the current working directory's absolute path from irb

I'm running Ruby on Windows though I don't know if that should make a difference. All I want to do is get the current working directory's absolute path. Is this possible from irb? Apparently from a script it's possible using

File.expand_path(__FILE__)


But from irb I tried the following and got a "Permission denied" error:

File.new(Dir.new(".").path).expand

Answer

Dir.pwd seems to do the trick.

http://ruby-doc.org/core/Dir.html#method-c-pwd