From: cdc@...2go.com (Cliff Cyphers) Date: 2006-06-26T09:13:05+09:00 Subject: Re: Stumped:beginners question --LQksG6bCIzRHxTLp Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Jun 26, 2006 at 08:57:05AM +0900, Pete Yandell wrote: > I'm just going to rewrite this, because there are a bunch of bad =20 > things in it. >=20 > def ask(question) > response_is_valid =3D false > result =3D false > while !response_is_valid > puts question > reply =3D gets.chomp.downcase > case reply > when 'yes' > result =3D true > response_is_valid =3D true > when 'no' > result =3D false > response_is_valid =3D false > else > puts 'Please answer "yes" or "no".' > end > end > result > end > much simpler than using the case statement: def ask(question) puts question reply =3D gets.strip.downcase while ("#{reply}" !=3D "yes") && ("#{reply}" !=3D "no") puts 'please answer "yes" or "no"' puts question reply =3D gets.strip.downcase end end --LQksG6bCIzRHxTLp Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (GNU/Linux) iD8DBQFEnyaOpXfXwRYlDA0RAiE7AJ9GKD5D1niLEAnTWTon0r3P5KJn3gCfe9Pk 7g/fY6+30CtnCbzr6+18bVI= =MFwi -----END PGP SIGNATURE----- --LQksG6bCIzRHxTLp--