From: Jesse Merriman Date: 2007-05-11T02:39:51+09:00 Subject: Re: instance_variables doesn't return unassigned variables On Thursday 10 May 2007 06:00, Bernd wrote: > Hi, > I wrote a code like this. > > class ABC > attr_accesor :first, :second > end > > when I wrote the following: > > x = ABC.new > x.first = "test" > puts x.instance_variables > > the output was only > > @first You could deduce them by looking for methods that end in an equals: irb(main):001:0> class ABC irb(main):002:1> attr_accessor :first, :second irb(main):003:1> end => nil irb(main):004:0> x = ABC.new => # irb(main):010:0> x.methods.select { |m| /[\w_]+=$/.match m } => ["second=", "first="] From there just strip of the = and prepend a @. -- Jesse Merriman jessemerriman@warpmail.net http://www.jessemerriman.com/