From: Dossy Date: 2003-01-09T02:15:27+09:00 Subject: Re: prompt On 2003.01.09, TOTO wrote: > Is there a Ruby idiom to do prompting? For example, > > ../rm.rb: remove `t'? y > > ? > > I find it rather troublesome to do that. I have to use something like: > > def prompt(file) > print "#{$0}: remove `#{file}'? " > decision = STDIN.getc > STDIN.getc # Get rid of the ending "\n" > return decision > end > > And it is not that safe in fact. If the user enter "Yes\n", the program will crash. > > Can someone suggest a better solution? def prompt(file) print "#{$0}: remove `#{file}'? " STDIN.readline.chomp end -- Dossy -- Dossy Shiobara mail: dossy@panoptic.com Panoptic Computer Network web: http://www.panoptic.com/ "He realized the fastest way to change is to laugh at your own folly -- then you can let go and quickly move on." (p. 70)