Actions
Bug #9815
closedattr_reader doesn't warn on a uninitialized instance variable
Description
attr_reader で定義したメソッドでは、-w 時に、未設定の警告「warning: instance variable @bar not initialized」みたいなのが出ないんですが、そういうもんでしょうか。
class C
attr_reader :foo
def bar; @bar; end
end
C.new.foo
C.new.bar #=> t.rb:4: warning: instance variable @bar not initialized
この例では、foo と bar は、同じ意味だと思って居たのでびっくりした次第です。
Updated by nobu (Nobuyoshi Nakada) over 10 years ago
- Status changed from Open to Closed
意図的なものです。
rb_ivar_get
とrb_attr_get
の差です。
Updated by ko1 (Koichi Sasada) over 10 years ago
どういう意図でしたっけ。
ちょっとググったけど見当たらず。
Updated by usa (Usaku NAKAMURA) over 10 years ago
- Status changed from Closed to Feedback
Updated by naruse (Yui NARUSE) almost 7 years ago
- Target version deleted (
2.2.0)
Updated by ko1 (Koichi Sasada) almost 5 years ago
- Status changed from Feedback to Rejected
Updated by Eregon (Benoit Daloze) over 4 years ago
What was the rationale here to have different behavior?
Which C function is used by attr_reader
seems an implementation detail.
Actions
Like0
Like0Like0Like0Like0Like0Like0