#2347·pry

如果 Dir.pwd != __dir__, whereami 将不起作用

作者: michaeleisel创建于 2025年3月14日更新于 2025年3月14日

我使用的是 Ruby 3.4.1 和 Pry 0.14.2 版本。当我运行 `my_script.rb` 并在运行 `Dir.chdir("/some/other/path")` 后遇到 `binding.pry` 语句,并尝试 `whereami` 时,它会失败,抱怨无法找到 `/some/other/path/my_script.rb`。看起来它在使用 Dir.pwd + basename,而应该使用 `__dir__` + basename。