4

为什么chdir自 ruby​​ 1.8.1 以来 Pathname 的方法已过时?它有什么问题?

这个:

dir = Pathname('a')
dir.chdir do
  ...
end

比这更短且更具可读性:

dir = Pathname('a')
Dir.chdir(dir) do
  ...
end
4

2 回答 2

1

它没有任何问题,Pathname只是不是适合它的地方。

改为使用Dir.chdir

来源:http ://corelib.rubyonrails.org/classes/Pathname.html#M000633 (点击“[Source]”)

于 2010-12-02T04:31:05.237 回答
0

还有FileUtils.cd('/', :verbose => true)

于 2010-12-02T06:22:48.050 回答