From: James Britt Date: 2008-05-03T03:40:22+09:00 Subject: Re: many attributes, same behavior Paul Winward wrote: > I'm wondering if there's an interpreter-checked method of doing this. > I'd like to something like: > > attr_reader :state, :error {|var| # get value of var from file}, or > attr_writer :state, :error {|var, value| # write "VAR value" in file } > > I realize this isn't possible, but are there any elegant solutions to > accomplish the same behavior? Have you tried writing your own versions of attr_reader and attr_writer? "attributes" are simply methods; the built-in attr_* methods dynamically create them for you class instances, and this is something you can do yourself by adding a class method to your class. -- James Britt http://www.rubyaz.org - Hacking in the Desert http://www.jamesbritt.com - Playing with Better Toys