【发布时间】:2015-12-05 01:36:25
【问题描述】:
在针对这段代码运行 Rubocop 后,我得到了
Use a guard clause instead of wrapping the code inside a conditional expression.
所以从我读过的内容来看,如果条件不满足,“保护条款”将退出该方法,所以我们不必浪费时间去处理额外的条件,如果我的理解不正确,请纠正我.
我的问题是我将如何使用具有多个条件的保护语句
def auth_creds
if %w(test1 qa demo ci).include? ENV['ENV']
{ key: 'key1', secret: 'secret1' }
elsif ENV['ENV'] == 'live'
{ key: 'key2', secret: 'secret2' }
else
fail 'Unable to set key/secret'
end
end
谢谢
【问题讨论】:
-
"针对此代码运行 Rubocop" - 真的是 this 代码吗?我没有收到该消息。
标签: ruby guard-clause