From: beny 18241 Date: 2009-12-20T03:20:33+09:00 Subject: Re: simple one Hi i used both methods and they works (thanks for that), but i have ine more question (both methods are affected) see my code (example) --- #!/usr/bin/ruby def ask(prompt) loop do print prompt, ' ' $stdout.flush s = gets exit if s == nil s.chomp! if s == 'y' or s == 'yes' return true elsif s == 'n' or s == 'no' return false else $stderr.puts "Please answer yes or no." end end end ask(' => ') --- i Saved it as a file.rb, as there is a small part of my bigger scirpt , i wanted to add argument, so i'am running it with argument(which is used later in my script): ./file.rb file.xml and i recive => Please answer yes or no. => Please answer yes or no. => Please answer yes or no. => Please answer yes or no. => Please answer yes or no. => Please answer yes or no. => Please answer yes or no. ... I know that I should clear input or something like that, but i dont know how , I' ve tried many ways. Please help Regards beny18241 Simeon Willbanks wrote: > I've written a simple program which I believe meets your requirements. > I've changed the text a bit, but I hope the code is helpful. > > Simeon > > class Choice > def initialize > @choices = ['y', 'N'] > @instructions = 'make a choice '+ @choices.join('/') > @response = 'you have choosen %s'+"\n"+'Goodbye' > end > def ask() > puts @instructions > STDOUT.flush > @input = gets.chomp > self.respond() > end > def respond() > if @choices.include?(@input) > puts @response % @input > STDOUT.flush > else > self.ask() > end > end > end > > c = Choice.new > c.ask() -- Posted via http://www.ruby-forum.com/.