我正在学习 Michael Hartl 的 Rails 类(class),on chapter 4 , 我的函数 full_title 如下:
app/helpers/application_helper.rb
module ApplicationHelper
def full_title page_title = ""
base_title = t "app_name"
page_title.empty? ? base_title : page_title + " | " + base_title
end
end
运行 reek(代码审查工具),我收到警告:
app/helpers/application_helper.rb -- 1 warning:
[4, 4]:FeatureEnvy: ApplicationHelper#full_title refers to 'page_title' more than self (maybe move it to another class?) [https://github.com/troessner/reek/blob/master/docs/Feature-Envy.md]
那么什么是FeatureEnvy以及在这种情况下如何修复它?
最佳答案
documentation of reek解释功能嫉妒如下:
Feature Envy occurs when a code fragment references another object more often than it references itself, or when several clients do the same series of manipulations on a particular type of object.
在这种特殊情况下,我认为这个问题可以忽略。辅助方法很自然地会接受参数并对其进行操作,而不是引用 self
(在本例中是 View 对象)。
如何从 reek 的分析中排除助手:
您应该能够通过将其添加到 config.reek 来排除所有助手是否符合“功能羡慕”规则。 文件:
"app/helpers":
FeatureEnvy:
enabled: false
关于ruby-on-rails - Rails-FeatureEnvy : ApplicationHelper#full_title refers to 'page_title' more than self (maybe move it to another class?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45039413/