Hi,
Tue, 24 May 2005 18:54:14 +0900,
Kirill Shutemov wrote in [ruby-talk:143518]:
No, I mean that such metod can be used for build and usage message an= d
options dependences together.
What I disposed is "mini-language" like it.
Why?
=20
=20
I think because the dependency can be arbitrarily complex, so any
language would have to be extended until it is turing complete. So it
is easier to use ruby in the first place, because no new syntax is
introduced. If you want, you can easily write your own mini-language
for your special application.
Simply create an object descendent from OptionParser that contains
your settings as accessors. Include a check routine and call this
after parsing
I made a small example. Maybe something like this can go into the
OptionParser documentation. I think the option parser example at the
moment is great but a bit overwhelming.
best regards,
Brian
#!/usr/bin/ruby
require 'optparse'
class MyOptions < OptionParser
attr_accessor

1,

2
def initialize(args =3D ARGV)
super(args)
=20
self.on("--o1", "Option 1") do self.o1 =3D true end
self.on("--o2", "Option 2") do self.o2 =3D true end
self.parse!(args)=20
self.check =20
end
=20
def check
raise "Don't specify o1 and o2 at the same time" if self.o1 and self.o2
raise "Specify at least on out of o1 or o2" unless self.o1 or self.o2
end
end
options =3D MyOptions.new
puts "o1 specified" if options.o1
puts "o2 specified" if options.o2
--=20
http://ruby.brian-schroeder.de/
Stringed instrument chords:
http://chordlist.brian-schroeder.de/