Noob问题.我在包含这个类的文件上运行了
Rubymine的Code Inspect.
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 calledname=
to set the attribute. String arguments are converted to symbols.
对我来说,“定义”意味着它有一个“声明”.警告信息没有意义. “警告:使用前字段可能未初始化”更准确.
我认为这是一个Rubymine问题(如果它是一个问题). RubyMine apparently uses its own code inspection protocol并且不使用标准Linter.