From: Eric Hodel Date: 2005-06-05T09:10:51+09:00 Subject: Re: ruby-dev summary 26128-26222 (Re: ropt/optparse) On 04 Jun 2005, at 14:15, a slow loriswithpoisonelbows wrote: > Eric Hodel writes: > >> For files with very few options, optparse requires too much typing. >> > > I don't think so. It seems to me you can leave out a great quantity of > the optparse pooky if you want to keep things simple: > > > require 'optparse' > require 'ostruct' > opt = OpenStruct.new > p = OptionParser.new {|p| > p.on('-c C') {|o| opt.color = o} > p.on('-i I', Integer) {|o| opt.int = o} > }.parse! > puts "color is: #{opt.color} (#{opt.color.class})" > puts "integer is: #{opt.int} (#{opt.int.class})" 6 lines too many (counting my shebang with -s): $ cat x.rb #!/usr/local/bin/ruby -ws puts "color is #{$c}" if defined? $c puts "integer is #{$i}" if defined? $i $ ./x.rb -c=blue -i=99 color is blue integer is 99 > Maybe the problem is with optparse documentation. I started with the > comment in the code and kept chucking until I got to what is above. You could also replace OpenStruct with a Hash. -- Eric Hodel - drbrain@segment7.net - http://segment7.net FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04