gpt4 book ai didi

ruby - 检查警告 : Cannot find declaration for field

转载 作者:数据小太阳 更新时间:2023-10-29 07:15:03 27 4
gpt4 key购买 nike

菜鸟问题。我对包含此类的文件运行了 RubyMine 的代码检查。

class Square
attr_accessor :width

def area
@width * @width
end
end

我很惊讶地在 @width * @width 行收到两个警告:

找不到字段“@width”的声明

attr section of the Style Guide对我没有帮助。为什么这是一个警告?

----编辑----
Ruby-Doc说到 attr-accessor

Defines a named attribute for this module, where the name is symbol.id2name, creating an instance variable (@name) and a corresponding access method to read it. Also creates a method called name= to set the attribute. String arguments are converted to symbols.

对我来说,“定义”意味着它有一个“声明”。警告消息没有意义。 “警告:字段在使用前可能未初始化”更准确。

我认为这是一个 RubyMine 问题(如果它真的是一个问题的话)。 RubyMine apparently uses its own code inspection protocol并且不使用标准的 Linter。

最佳答案

RubyMine 在这种情况下显示的警告是 known issue .

关于ruby - 检查警告 : Cannot find declaration for field,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37738412/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com