From: RichardOnRails Date: 2010-02-02T07:55:09+09:00 Subject: Re: Workaround for "conflict" between ARGV and gets? On Feb 1, 1:18 am, Ryan Davis wrote: > On Jan 31, 2010, at 20:15 , 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 !!! > > ri IO.gets > ri Kernel.gets I see, Ryan. What I should have done to understand the problem fully was: puts gets.class # => String which makes it clear why I didn't get the 'native' versions you pointed out. I had checked in http://www.ruby-doc.org/core/ but made two stupid mistakes: I failed to notice Kernel in the middle column and gets (Kernel) in the right-hand column. And I never thought of IO, nor noted gets (IO) in the right-hand column. It all begs the question: When will I learn enough Ruby to program without you guys :-) Best wishes, Richard