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

Dir.pwd seems to do the trick.

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


File.expand_path File.dirname(__FILE__) will return the directory relative to the file this command is called from.

But Dir.pwd returns the working directory (results identical to executing pwd in your terminal)


As for the path relative to the current executing script, since Ruby 2.0 you can also use

__dir__

So this is basically the same as

File.dirname(__FILE__)