optparse: on() vs on_tail()

  • Thread starter James Edward Gray II
  • Start date
J

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.

James Edward Gray II
 
E

Eric Hodel

--Apple-Mail-52-514739234
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=US-ASCII; format=flowed

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 - (e-mail address removed) - http://segment7.net
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

--Apple-Mail-52-514739234
content-type: application/pgp-signature; x-mac-type=70674453;
name=PGP.sig
content-description: This is a digitally signed message part
content-disposition: inline; filename=PGP.sig
content-transfer-encoding: 7bit

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Darwin)

iD8DBQFCJnxJMypVHHlsnwQRAnLmAJ9kc6YZ1V6FEEcdhh2GaSmQflVZBgCgxn66
O3iMnECXq3gRhcbpO5x4HK4=
=mXMA
-----END PGP SIGNATURE-----

--Apple-Mail-52-514739234--
 
J

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.

It looks like on_tail only exists to make things pretty.

Thanks much.

James Edward Gray II
 
J

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
 
T

Thomas Kirchner

--J2SCkAp4GZ/dPZZf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

* On Mar 3 12:22 said:
While we're on the subject, if you just use on(), are options added to=20
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.ht=
ml
Hope that helps.
Tom

--J2SCkAp4GZ/dPZZf
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)

iD8DBQFCJw03/rVdTqQq7OwRAgXjAJ9XAeDG5IHM8ovqF1v8BCdGyav1MgCfcuoM
ZMMUaarD0YdDTESoFEX6iLE=
=HeL/
-----END PGP SIGNATURE-----

--J2SCkAp4GZ/dPZZf--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top