From: Robert Klemme Date: 2005-01-25T01:25:52+09:00 Subject: Re: attr "Trans" schrieb im Newsbeitrag news:1106574588.198173.83840@f14g2000cwb.googlegroups.com... > In the upcoming release of Ruby Carats I have a little lib called > attr.rb. > > What it does is define a mater #define_attribute which all attribute > defintions are routed thru. Then I redefine #attr (since current > definition is basically never used) to call #define_attribute that > takes multiple args. Here's an example: > > . attr :a, :a= > > which is equivalent to: > > . attr_reader :a > . attr_writer :a > > It also has some extra freatures that are nice like: > > . attr :a?, :b! > > which is the same as > > . def a? > . @a ? true : @a > . end Why not "def a?() @a end"? > . def b!(x) > . @b.replace x > . end Hm, I don't like that because it's too special case. Also you might want to be able to assign and to replace... > Also these return an array of the symbols of the methods that get > defined, so you can use public, private, protected on them. eg. > > . private attr :a > > There are a couple of other features too, but I'll leave those aside > for now, as they are not important to this inquery. > > So I have a few questions. First, what do you think of this in general? > Second, there is no "extra" convenient way to do an accessor b/c I > haven't been able to find a nice notation --one just has to put both, > 'attr :a, :a='. Is this too inconvenient? Can anyone think of a good > notation? Although I find "attr_accessor" quite lengthy, I don't really see the benefit of your proposal. And attr_accessor does indeed define reader and writer for several attributes... Kind regards robert