From: Natevw Date: 2006-05-16T11:22:48+09:00 Subject: Re: learn to program corey konrad wrote: > oh ok he is just talking about variable scope it was kind of hard to > tell from his example for some resaon, i dont know i think i am going to > skip this learn to program book, this chris guy really doesnt know how > to explain things to a person with a beginner mind set. From what I've seen so far, I think you could find better. > i also am having > problems running his code examples i really dont understand how the > code below works but when i copy and paste it into the live ruby program > all it does is close the live ruby program and shuts it down. > > def ask question > good_answer = false > while (not good_answer) > puts question > reply = gets.chomp.downcase > if (reply == ' yes' or reply == ' no' ) > good_answer = true > if reply == ' yes' > answer = true > else > answer = false > end > else > puts ' Please answer "yes" or "no".' > end > end > answer # This is what we return (true or false). > end > This pastes fine into my version of 'irb'. You seem to have a couple of extra spaces, but that shouldn't close the program. Does the author really not indent his examples? If so that's another reason to find a better book. Here it is indented, that might help you understand it. def ask question good_answer = false while (not good_answer) puts question reply = gets.chomp.downcase if (reply == 'yes' or reply == 'no' ) good_answer = true if reply == 'yes' answer = true else answer = false end else puts ' Please answer "yes" or "no".' end end answer # This is what we return (true or false). end answer = ask "Is this working?" (keep scope in mind for the last 'answer') It seems that your beginner guide is a bit too "friendly" and keeps you from important details that you'll need to learn soon anyway. Have you looked at the "Programming Ruby" book? I had plenty of programming experience before going to it, so YMMV, but it at least keeps things concise. Try the 1st edition on for size here: http://www.rubycentral.com/book/intro.html I'd recommend looking for a book that's understandable, but doesn't fudge the details. Otherwise, my method of choice is to learn a bit, then try writing things on my own, which always forms questions, which leads to more searching/reading/learning. -natevw