如何使用 ruby 获取没有最后一个文件夹的路径?

How do I get the path without the last folder using ruby?

给出的例子:

我的路径是(由Dir.pwd给出)"D:/home/usr/documents/text files/2016"

有什么简单的方法可以获取没有最后一个子文件夹的路径。

结果应该是:"D:/home/usr/documents/text files"

目前我在做这个 路径 = Dir.pwd.reverse.partition("/")[-1].reverse

可行,但我想我错过了更好的方法。

提前致谢!

File.expand_path("..", Dir.pwd)