Why was Pathname's chdir method obsoleted?
Why is Pathname's chdir
method obsoleted since ruby 1.8.1? What is wrong with it?
This:
dir 开发者_开发知识库= Pathname('a')
dir.chdir do
...
end
is shorter and more readable than this:
dir = Pathname('a')
Dir.chdir(dir) do
...
end
Nothing is wrong with it, Pathname
just wasn't the right place for it.
Use Dir.chdir
instead.
Source: http://corelib.rubyonrails.org/classes/Pathname.html#M000633 (click "[Source]")
There's also FileUtils.cd('/', :verbose => true)
精彩评论