微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐