Optparse and gets

Hi,

I'm using optparse.
At a certain point in the program, I need a confirmation (exept if --no-confirm is used as argument).

Here's a program illustrating my question:

#!/usr/bin/env ruby

require 'optparse'

opts = OptionParser.new
opts.on("--no-confirm" ) { |val| confirm=false }

puts "enter string:"
s = gets
puts "you entered #{s}"

when calling this script without any argument, it runs fine.
But once I pass it the --no-confirm argument, if fails with this message:

../test.rb:9:in `gets': No such file or directory - --no-confirm (Errno::ENOENT)
         from ./test.rb:9

I have fixed the problem by calling $stdin.gets instead. But I don't see
what caused the problem in the first place, and I'm curious enough to send a message here :wink:

thanks for any indication.

Raph

Hi,

At Wed, 29 Dec 2004 05:56:47 +0900,
Bauduin Raphael wrote in [ruby-talk:124673]:

#!/usr/bin/env ruby

require 'optparse'

opts = OptionParser.new
opts.on("--no-confirm" ) { |val| confirm=false }

  opts.parse!(ARGV)

···

puts "enter string:"
s = gets
puts "you entered #{s}"

--
Nobu Nakada