On Mon, Feb 17, 2003 at 10:46:59AM -0800, Bill Kelly wrote: > > How can I make it test that the instance variable is uninitialised, so I can > > prevent a warning? > > I think defined? might do the trick: OK, how about this one :-) I have a Struct, and have dynamically added a new member. I want to check whether the instance variable corresponding to that attribute is already initialised. How can I do that? Example: foo = Struct.new("Foo", "a", "b", "c") obj = foo.new newmember="d" foo.module_eval { attr_accessor newmember } obj.send("#{newmember}=", []) if obj.send(newmember).nil? # *** obj.send(newmember)<< "hello" puts obj.send(newmember) How can I write the line '***' so it does not generate a warning under -w ? Note that 'respond_to?' is not the answer, because the accessor methods do exist - it's just the associated instance variable which has not been initialised. Cheers, Brian.