From: Robert Dober Date: 2007-05-11T06:58:48+09:00 Subject: Re: instance_variables doesn't return unassigned variables On 5/10/07, Jesse Merriman wrote: > 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: Hmm that might not be a good idea, a method ending in equals does not induce the creation of an instance variable with that name. One could however put attr on steroids by creating a list of attributes for the class. Look at this quick and dirty hack do see if this could be helpfull for you class Module alias_method :orig_attreader, :attr_reader def attr_reader *symbols @__atts__ ||= superclass.attributes.dup @__atts__ += symbols @__atts__.uniq! orig_attreader *symbols end def attributes @__atts__ || [] end end class A attr_reader :a attr_reader :a, :b puts attributes.join(", ") end class B < A attr_reader :c def initialize @c = 42 end puts attributes.join(", ") end puts B.new.c > HTH Robert -- You see things; and you say Why? But I dream things that never were; and I say Why not? -- George Bernard Shaw