From: "David A. Black" Date: 2007-03-18T22:00:01+09:00 Subject: Re: attr_accessor Hi -- On 3/18/07, Clifford Heath wrote: > Corey Konrad wrote: > > wow this attr_accessor thing is really great i can see this saving ALOT > > of typing. > > If you want to check that assigned values are valid at the > time of assignment (instead of later during validation), > please consider using "typed_attr" from my "chattr" gem. > > gem install chattr > > class Foo > typed_attr String :bar do |v| v.size <= 20 end > end > > Now you can't assign a string that's nil or more than 20 characters > without an exception being thrown. Wouldn't it be better to call that checked_attr? I'm just thinking that it's mostly checking the class, rather than the type (though calling size on it implicitly means that it's of type "object that has a size method"), so a more generic name might be good. David -- Q. What is THE Ruby book for Rails developers? A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black) (See what readers are saying! http://www.rubypal.com/r4rrevs.pdf) Q. Where can I get Ruby/Rails on-site training, consulting, coaching? A. Ruby Power and Light, LLC (http://www.rubypal.com)