加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-17 03:25:01 所属栏目:百科 来源:网络整理
导读:Noob问题.我在包含这个类的文件上运行了 RubyMine的Code Inspect. class Square attr_accessor :width def area @width * @width endend 我很惊讶在@width * @width线上收到两条警告: 无法找到字段’@width’的声明 attr section of the Style Guide对我没
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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读