In article <20030217183329.A78444 / linnet.org>,
Brian Candler  <B.Candler / pobox.com> wrote:
>I have an existing class Foo, and existing objects of that class.
>
>I now extend the class by adding a method, which makes use of an instance
>variable which previously did not exist.
>
>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)
>

If I understand what you're trying to do, then you need to test to see if 
@things is defined, like:

if defined?(@things)
  @things << n
else
  @things = []
end

Phil