【发布时间】:2017-05-27 10:33:21
【问题描述】:
类上的这个简单方法只需使用安全导航运算符运行status 方法。
def current_status
account&.status
end
但是臭臭的报告这个警告:
MyClass#current_status performs a nil-check [https://github.com/troessner/reek/blob/master/docs/Nil-Check.md]
如何正确编写这样的方法来避免 Nil Check?
我还从thoughtbot 验证了this post,但对于安全导航操作员来说似乎“太多”了。
Ruby 2.3.1
【问题讨论】:
-
就像 reek 说的,这个
mask bigger problems in your source code like not using OOP and / or polymorphism when you should。我认为您需要显示更多代码,至少是包含 current_status 方法的类的相关部分。
标签: ruby ruby-2.3.1 reek safe-navigation-operator