From: Konrad Meyer Date: 2007-11-19T06:43:38+09:00 Subject: Re: [QUIZ] Goedel (#147) --nextPart4303886.kIE10lVdbL Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Quoth Eric Lavigne: > On Nov 18, 2007 3:42 PM, steve wrote: > > there's an instance var @primes which has the list of already generated > > primes, @primes.last would do it > > >=20 > Sounds simple enough, but accessing instance variables seems to be a > rather verbose operation. >=20 > Here is what it should look like (if the Prime class worked the way I > originally expected): > primes =3D Prime.new > primes.next.doSomething > primes.last.doSomethingElse >=20 > Here was my first attempt using your suggestion, which looks > reasonable but doesn't work. > primes =3D Prime.new > primes.next.doSomething > primes.@primes.last.doSomethingElse >=20 > Here is what finally worked, but I can't believe the verbosity of the > final line. Is there a shorter way? yes. > primes =3D Prime.new > primes.next.doSomething > primes.instance_variable_get("@primes").last.doSomethingElse Instead of doing that, you could just extend the Prime class: class Prime def this @primes.last end end primes =3D Prime.new primes.next.doSoemthing primes.this.doSomethingElse That should work how you want, yes? >=20 > --=20 > There are two ways of constructing a software design: One way is to > make it so simple that there are obviously no deficiencies, and the > other way is to make it so complicated that there are no obvious > deficiencies. The first method is far more difficult. >=20 > - C.A.R. Hoare - >=20 HTH, =2D-=20 Konrad Meyer http://konrad.sobertillnoon.com/ --nextPart4303886.kIE10lVdbL Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (GNU/Linux) iD8DBQBHQLH2CHB0oCiR2cwRAiW3AJoCQIOuimLNpwybGNzrSjzgTSdqmwCfUO0x +AOT+BiRoBlv4T9nZOAdcdI= =oxqU -----END PGP SIGNATURE----- --nextPart4303886.kIE10lVdbL--