我有一个包含类变量的Ruby类,但是RuboCop不喜欢这个,因为我收到了警告:在Ruby中使用类变量被认为是一种糟糕的代码风格。我想在我的全局配置中禁止此警告,这就是我尝试以下操作的原因:
Style/ClassVars:
Enabled: false
这似乎没有任何改变,因为我仍然看到警告。我的全局配置中的所有其他设置都运行正常。我在这里缺少什么?
编辑:这是我所指的场景,其中类变量用户标有警告。
class User
@@users = []
def initialize(name)
@name = name
@@users.push(self)
end
def self.list_users
@@users.each { |user| puts user }
end
end
User.new('Alice')
User.new('Bob')
User.list_users
答案 0 :(得分:2)
我在RubyMine中粘贴了你的代码,我看到了相同的警告,但这不是RuboCop的警告。 RubyMine有自己的linter。
参见偏好设置 - >检查 - > Ruby - >类变量用法