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

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


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__)