From: Gavin Sinclair Date: 2005-11-08T12:07:11+09:00 Subject: Re: CommandLine-0.7.10 Jim Freeze wrote: > > * I want to write an application that inherits a different class. Can > > I still use this library? > > Good question. Can you give me an example. Say I have a company-specific application class (which I don't, but let's pretend) called AcmeApp, which all applications are to inherit. Say I also want to use your library. I'd like to see the option parsing be independent of the application. Perhaps something like this: class AppOptions < CommandLine::OptionParser author "Gavin Sinclair" description "blah blah blah" options :help, :debug option :names => %w(--remove -R), # ... expected_args :file end class App < AcmeApp def App.run(args) options = AppOptions.parse(args) if options.debug ... elsif options.remove ... end end end App.run(ARGV) > When I created this there was much debate over whether > to make this a module or a class. IIRC, class was used > becuase it was thought that any mixed in functionality > should really go in its own class to have SOI. The app > class is really just to handle the interface with the user. > So, a standard app would look like so: > > class MyApp < CommandLine::Application > def initialize > end > def main > # keep SOI > MyBigWorkingClass.new(@option_data) > end > end Oh I see... A few small applications I'm working have a common base class. I'll see if I can rearrange the code or otherwise get it working with the CommandLine library. Otherwise I might have some more specific suggestions. Cheers, Gavin