From: "Mauricio Fernández" Date: 2003-01-08T08:26:13+09:00 Subject: Re: attr_cast, one a small step for interface techniques On Tue, Jan 07, 2003 at 08:51:58PM +0900, Tom Sawyer wrote: > On Tuesday 07 January 2003 01:14 am, Mauricio Fern�ndez wrote: > > > def attr_reader(*args) > > > if args.last.kind_of?(Hash) or args.last.kind_of?(Array) > > > attr_reader_with_cast(args.pop) > > > end > > > attr_reader_basic(*args) > > > end > > > > > > def attr_reader_with_cast(harg) > > > harg.each { |name, cast| > > > > What happens when harg is an Array? > > perhaps that should be removed. i had thought one could do this: > > attr_accessor [ [:avar, :to_s], ...] > > but that's rather pointless isn't it? i had only thought of allowing it b/c > the same code works with it as does for Hash, i.e. harg.each { |name, cast| > ... } It's more error-prone than '=>': even though it represents the same number of keypresses, it's anyway another '[' to match... At any rate, w/ or w/o Array, this casting attr_reader is great! -- _ _ | |__ __ _| |_ ___ _ __ ___ __ _ _ __ | '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ | |_) | (_| | |_\__ \ | | | | | (_| | | | | |_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_| Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com Not only Guinness - Linux is good for you, too. -- Banzai on IRC