[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

optparse: on() vs on_tail

James Gray

3/3/2005 2:45:00 AM

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



4 Answers

Eric Hodel

3/3/2005 2:54:00 AM

0

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 - drbrain@segment7.net - http://se...
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

James Gray

3/3/2005 3:01:00 AM

0

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 Gray

3/3/2005 3:22:00 AM

0

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

3/3/2005 1:12:00 PM

0

* On Mar 3 12:22, James Edward Gray II (ruby-talk@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/OptionP...
Hope that helps.
Tom