加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 20:01:28 所属栏目:百科 来源:网络整理
导读:我想在另一个目录中运行多个命令(或更容易),然后一旦完成,返回到上一个工作目录. 我设想的东西与Fabric’s with cd(path): 类似,例如: cd('.git') do File.unlink('config')end 在耙子中是否有内置的方式,或者我应该编写一个接受块等的自定义方法? 解决方
我想在另一个目录中运行多个命令(或更容易),然后一旦完成,返回到上一个工作目录.

我设想的东西与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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读