简体   繁体   English

Ruby Lint错误使用Guard子句编写此代码的正确方法是什么

[英]Ruby lint error what is the right way to write this with a guard clause

Trying to run a command, if success continue on, if failure raise error and send commands output to console. 尝试运行命令,如果成功继续,如果失败引发错误,然后将命令输出发送到控制台。

output = `#{command}`
unless $CHILD_STATUS.success?
  raise "#{command} failed with:\n#{output}"
end

C: Use a guard clause instead of wrapping the code inside a conditional expression.

the code functions correctly but, rubocop doesn't like it. 该代码可以正常运行,但是rubocop不喜欢它。 What would be the best way to improve the style of this code and still give me the same functionality? 改进此代码样式并仍然给我相同功能的最佳方法是什么?

尝试这个

raise "#{command} failed with:\n#{output}" unless $CHILD_STATUS.success?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM