Brian Candler <B.Candler / pobox.com> writes: > 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 This won't generate a warning. def add_thing(n) @thing ||= [] @thing << n end -- matt