From: Brian Candler Date: 2009-05-20T21:28:14+09:00 Subject: Re: optparse: Arguments as Arguments Unexpectedness Ben Woodcroft wrote: > I am trying to use the standard optionparser to read in some arguments, > but one of those arguments is an argument itself. Is this a bug? I don't think so. I think it's an ambiguity because you have declared your -a flag to take an *optional* argument. Suppose your OptionParser also honoured the -d option. It would need to choose between "-a" with argument "-d me", and "-a" with no argument followed by option "-d" with argument "me". OptionParser is taking the view that anything which starts with a dash in that case is intended to be the next option on the line. Otherwise, the argument to the -a flag would hardly be optional if it always consumed the next string. If your -a option *always* takes an argument, then declare it as such, without the square brackets: require 'optparse' OptionParser.new do |opts| opts.on('-a','--args ARGUMENTS',String,"arguments") {|v| puts "Found: #{v}"} end.parse! $ ruby opt.rb -a "-d me" Found: -d me Otherwise, your original code works as long as you include the flag and its argument in the same position. $ ruby opt.rb "-a-d me" Found: -d me -- Posted via http://www.ruby-forum.com/.