James Edward Gray II
> Can someone tell me the difference between the on() and on_tail()
> methods of OptionParser. I can't seem to figure it out. Thanks.
from optparse.rb:
=begin
--- OptionParser#on(*opts) [{...}]
--- OptionParser#def_option(*opts) [{...}]
--- OptionParser#on_head(*opts) [{...}]---
OptionParser#def_head_option(*opts) [{...}]
--- OptionParser#on_tail(*opts) [{...}]
--- OptionParser#def_tail_option(*opts) [{...}]
Defines option switch and handler. (({on_head})),
(({def_head_option}))
and (({on_tail})), (({def_tail_option})) put the switch at head
and tail of summary, respectively.
cf. ((<OptionParser#switch>)).
=end #'#"#`#
If you read down from there, on_tail/on add things to the end, of the
args list summary while on_head adds them to the front.
It looks like on_tail only exists to make things pretty.
--
Eric Hodel - drb...@segment7.net - http://segment7.net
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04
> If you read down from there, on_tail/on add things to the end, of the
> args list summary while on_head adds them to the front.
>
> It looks like on_tail only exists to make things pretty.
Thanks much.
James Edward Gray II
> If you read down from there, on_tail/on add things to the end, of the
> args list summary while on_head adds them to the front.
While we're on the subject, if you just use on(), are options added to
the summary in order? Thanks again.
James Edward Gray II
Yeah, they're added in the order that you declare them. on_head is useful
for general, common options that most everyone needs, so that they appear
first. on() adds everything to the middle in order. on_tail is good for
generic options like --help or --version that aren't vital, but should be
there. Or at least that's how I use it :)
There's some decent documentation and a good example here:
http://www.ruby-doc.org/stdlib/libdoc/optparse/rdoc/classes/OptionParser.html
Hope that helps.
Tom