From: Jan_K Date: 2006-04-03T09:08:44+09:00 Subject: Re: Learn to Program, by Chris Pine Chapter 9, exercise 1 (page 76) "Fix up the ask method. That ask method I showed you was alright, but I bet you could do better. Try to clean it up by removing the variables good_answer and answer. You�ll have to use return to exit from the loop. (Well, it will get you out of the whole method, but it will get you out of the loop in the process.) How do you like the resulting method? I usually try to avoid using return (personal preference), but I might make an exception here." Solution: -------------------------------------------------------------------------------------- def ask question while true puts question reply = gets.chomp.downcase if reply == 'yes' return true elsif reply == 'no' return false else puts 'Please answer "yes" or "no".' end end end puts 'Hello, and thank you for...' puts ask 'Do you like eating tacos?' ask 'Do you like eating burritos?' wets_bed = ask 'Do you wet the bed?' ask 'Do you like eating chimichangas?' ask 'Do you like eating sopapillas?' puts 'Just a few more questions...' ask 'Do you like drinking horchata?' ask 'Do you like eating flautas?' puts puts 'DEBRIEFING:' puts 'Thank you for...' puts puts wets_bed --------------------------------------------------------------------------------------