0

尝试运行命令,如果成功继续,如果失败引发错误并将命令输出发送到控制台。

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.

代码正常运行,但 rubocop 不喜欢它。什么是改进此代码样式并仍为我提供相同功能的最佳方法?

4

1 回答 1

0

尝试这个

raise "#{command} failed with:\n#{output}" unless $CHILD_STATUS.success?
于 2015-08-18T17:47:38.330 回答