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

Dexygen picture Dexygen · Dec 21, 2009 · Viewed 228k times · Source

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

user85509 picture user85509 · Dec 21, 2009

Dir.pwd seems to do the trick.

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