From: Jonathan Paisley Date: 2005-03-15T23:02:21+09:00 Subject: Re: OptionParser question On Tue, 15 Mar 2005 10:48:36 +0900, Jos Backus wrote: > OptionParser is still a mystery to me. In the example below, how do I > distinguish between a -c flag without an argument (which is a fatal syntax > error) and no -c flag at all? In both cases client equals nil. There doesn't > seem to be a way to intercept the `missing argument' message, or if there is, > I can't seem to find it in the documentation :-/ opt.parse! returns the remaining non-option arguments (which is in fact just ARGV at this stage, with options removed), or nil upon failure. This is propagated to the return value of ARGV.options. A common idiom seems to be: ARGV.options do |opt| ... ... opt.parse! end or exit 1 # ^^^^^^^^^