ruby – 检查警告:找不到字段的声明

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 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.

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...