From: Philipp Meier Date: 2002-09-30T07:24:52+09:00 Subject: Re: thoughts on typelessness --n+lFg1Zro7sl44OB Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Sep 29, 2002 at 12:09:32PM +0900, dblack@candle.superlink.net wrote: > You can also do this: >=20 > begin > a.meth > rescue NameError > ... >=20 > I've done that, for instance, in my dbdbd (database definer) program. > It uses 1-originating array notation to index columns, but can also > use field-names. So the reader method for the sort_key (for example) > is: >=20 > def sort_key > @sort_key - 1 > rescue NameError > @sort_key > end >=20 > which I think looks better than: >=20 > def sort_key > if @sort_key.respond_to?(:-) > @sort_key - 1 > else > @sort_key > end > end >=20 > or any of the many variants of that. But the rescue version is > relatively slow. I the NameError acutally might be thrown _inside_ @sort_key.- , because of an programming error e.g., not because the the method does not exist. So you must at least check for Exepction.backtrace.size =3D=3D 1. -billy. --=20 Meisterbohne S=F6flinger Stra=DFe 100 Tel: +49-731-399 499-0 eL=F6sungen 89077 Ulm Fax: +49-731-399 499-9 --n+lFg1Zro7sl44OB Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.0 (GNU/Linux) iD8DBQE9lzMhfBriNoqItSYRAga9AJwIyyr5g6+5sswbhuYxLNZ2jCWKFgCfWbKZ cUN+eHDd2kDXJJhIxPMKV2A= =Zwpv -----END PGP SIGNATURE----- --n+lFg1Zro7sl44OB--