Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

optparse: on() vs on_tail()

292 views
Skip to first unread message

James Edward Gray II

unread,
Mar 2, 2005, 9:45:19 PM3/2/05
to
Can someone tell me the difference between the on() and on_tail()
methods of OptionParser. I can't seem to figure it out. Thanks.

James Edward Gray II

Eric Hodel

unread,
Mar 2, 2005, 9:54:21 PM3/2/05
to
On 02 Mar 2005, at 18:45, James Edward Gray II wrote:

> 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

PGP.sig

James Edward Gray II

unread,
Mar 2, 2005, 10:01:20 PM3/2/05
to
On Mar 2, 2005, at 8:54 PM, Eric Hodel wrote:

> 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

James Edward Gray II

unread,
Mar 2, 2005, 10:22:19 PM3/2/05
to
On Mar 2, 2005, at 8:54 PM, Eric Hodel wrote:

> 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

Thomas Kirchner

unread,
Mar 3, 2005, 8:12:18 AM3/3/05
to
* On Mar 3 12:22, James Edward Gray II (ruby...@ruby-lang.org) wrote:
> While we're on the subject, if you just use on(), are options added to
> the summary in order? Thanks again.

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

0 new messages