title: Can OptionParser skip unknown options, to be processed later in a Ruby program?
body: <p>Is there any way to kick off <a href="http://www.ruby-doc.org/stdlib-1.9.3/libdoc/optparse/rdoc/OptionParser.html" rel="noreferrer">OptionParser</a> several times in one Ruby program, each with different sets of options?</p>
  
  <p>For example:</p>
  
  <pre><code>$ myscript.rb --subsys1opt a --subsys2opt b
  </code></pre>
  
  <p>Here, myscript.rb would use subsys1 and subsys2, delegating their options handling logic to them, possibly in a sequence where 'a' is processed first, followed by 'b' in separate OptionParser object; each time picking options only relevant for that context.
  A final phase could check that there is nothing unknown left after each part processed theirs.</p>
  
  <p>The use cases are:</p>
  
  <ol>
  <li><p>In a loosely coupled front-end program, where various components have different arguments, I don't want 'main' to know about everything, just to delegate sets of arguments/options to each part.</p></li>
  <li><p>Embedding some larger system like RSpec into my application, and I'd to simply pass a command-line through their options without my wrapper knowing those.</p></li>
  </ol>
  
  <p>I'd be OK with some delimiter option as well, like <code>--</code> or <code>--vmargs</code> in some Java apps.</p>
  
  <p>There are lots of real world examples for similar things in the Unix world (startx/X, git plumbing and porcelain), where one layer handles some options but propagates the rest to the lower layer.</p>
  
  <p>Out of the box, this doesn't seem to work. Each <code>OptionParse.parse!</code> call will do exhaustive processing, failing on anything it doesn't know about.
  I guess I'd happy to skip unknown options.</p>
  
  <p>Any hints, perhaps alternative approaches are welcome.</p>