From: RichardOnRails Date: 2010-02-02T07:35:08+09:00 Subject: Re: Workaround for "conflict" between ARGV and gets? On Feb 1, 1:24 am, Walton Hoops wrote: > On 1/31/2010 9:15 PM, RichardOnRails wrote: > > > > > gets looks to ARGV, if populated, for its source of data.  That is its > > documented behavior. > > > I want to: > > 1)  use ARGV to point to a directory I want to process and > > 2)  use gets to inquire whether the user wants the program to proceed > > with that directory. > > > I thought I might be able to reset ARGV to an empty array after I > > saved its content, but that doesn't work.  Is there a way around this. > > > The following code never pauses to allow the user to enter yes/no, as > > I intended it to.  Is there a workaround? > > > === Code == > > puts "ARGV = %s" % ARGV.join(", ") > > argv = ARGV[0]                     # Save ARGV's content > > ARGV = []                          # Reset ARGV to an empty array > > puts "Delete indicated item [yes, no]" > > STDOUT.flush > > response = gets.chomp      # doesn't go to STDIN !!! > > Change this line to 'STDIN.gets.chomp'.  Finit! > > > puts case response > >    when /^yes$/i; "Deleting" > >    when /^no$/i; "Quiting" > >    else; "Huh?" > >    end > > puts "EOJ" > > > puts "EOJ" > > Best, > Walton >> STDIN.gets.chomp Very cool: Just tell gets I want the STDIN flavor!! Many thanks, Walton - Richard