Simple Switch

A simple switch is an argument with no optional forms or no parameters. The effect will be to simply set a flag in the options hash. No other parameters will be passed to the on method.

options[:simple] = false
opts.on( ‘-s’, ‘–simple’, “Simple argument” ) do
options[:simple] = true

Switch with Mandatory Parameter

Switches that take a parameter only need to state the parameter name in the long form of the switch. For example, “-s”, “–simple Simple” means the -f or –file switch takes a single parameter called Simple, and this parameter is mandatory. You cannot use either -f or –file without also passing it a parameter.

options[:simple] = “”
opts.on( ‘-s’, ‘–simple Simple’, “simple with an argument” ) do|f|
options[:simple] = f

If without ‘Simple’ inside ‘–simple Simple’, the value of f will be switch value: true or false, rather than the real simplevalue in the command line”–simple simplevalue”


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s