From: Logan Capaldo Date: 2006-05-04T14:28:29+09:00 Subject: Re: Ruby idiom for attributes / properties On May 4, 2006, at 1:07 AM, John Lam wrote: > Excellent! > > Now the bigger question is - any chance this could become part of the > standard distribution? I could add another special case in my > bridge to > marshal traits auto-magically as well, but it would rock if this > mechanism > could be something that I could grab a hold of when reflecting > against Ruby > objects at the marshaling boundary. > > -John > http://www.iunknown.com You could do class Module alias old_attr_reader attr_reader alias old_attr_writer attr_writer alias old_attr_accessor attr_accessor def attr_reader(*args) self.attributes |= args old_attr_reader(*args) end def attr_writer(*args) self.attributes |= args old_attr_writer(*args) end def attr_accessor(*args) self.attributes |= args old_attr_accessor(*args) end def attributes @attribs ||= [] end def attributes=(new_attribs) @attribs = new_attribs end end class A attr_accessor :a end p A.attributes Note that you'd have to make sure this was required before anything else, and it only works for attributes declared with the attr_* family of methods