[Open] attr_reader doesn't warn on a uninitialized instance variable

Issue #9815 has been reported by Koichi Sasada.

Bug #9815: attr_reader doesn’t warn on a uninitialized instance variable

  • Author: Koichi Sasada
  • Status: Open
  • Priority: Normal
  • Assignee: Yukihiro M.
  • Category: core
  • Target version: current: 2.2.0
  • ruby -v: confirmed by 1.9.3-2.2.0
  • Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN

attr_reader で定義したメソッドでは、-w 時に、未設定の警告「warning: instance variable @bar not

class C
  attr_reader :foo
  def bar; @bar; end
C.new.bar #=> t.rb:4: warning: instance variable @bar not initialized

この例では、foo と bar は、同じ意味だと思って居たのでびっくりした次第です。

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs