On Tue, Feb 18, 2003 at 03:33:53AM +0900, Brian Candler wrote: > How can I make it test that the instance variable is uninitialised, so I can > prevent a warning? This is what I am trying to do: > > class Foo > attr_reader :things > def add_thing(n) > if @things.nil? > @things = [] > end > @things << n > end > end > > However, the test '@things.nil?' generates > 'warning: instance variable @things not initialized' > if ruby is running with -w. (This is 1.6.8) > > I am hoping that I don't have to keep track of all existing Foo objects, > just so that I can send them a message 'reset_things' >> class A >> def add_thing >> @foo ||= 'test' >> end >> attr_reader :foo >> end => nil >> A.new.foo (irb):7: warning: instance variable @foo not initialized => nil >> a = A.new => #<A:0x4021d7c8> >> a.add_thing => "test" >> a.foo => "test" -- _ _ | |__ __ _| |_ ___ _ __ ___ __ _ _ __ | '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ | |_) | (_| | |_\__ \ | | | | | (_| | | | | |_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_| Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com * LG loves czech girls. <vincent> LG: do they have additional interesting "features" other girls don't have? ;) -- #Debian