ruby – 暂时更改Rake的当前目录

我想在另一个目录中运行多个命令(或更容易),然后一旦完成,返回到上一个工作目录.

我设想的东西与Fabric’s with cd(path):类似,例如:

cd('.git') do
   File.unlink('config')
end

在耙子中是否有内置的方式,或者我应该编写一个接受块等的自定义方法

解决方法

它只是内置的Dir#chdir调用
Dir.chdir('.git') do
  File.unlink('config')
end

摘自docs

If a block is given,it is passed the name of the new current directory,and the block is executed with that as the current directory. The original working directory is restored when the block exits.

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...