微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐