NRuby
23 строки · 682.0 Байт
1basic.rb:
2# Require the OptionParser code.
3require 'optparse'
4# Create an OptionParser object.
5parser = OptionParser.new
6# Define one or more options.
7parser.on('-x', 'Whether to X') do |value|
8p ['x', value]
9end
10parser.on('-y', 'Whether to Y') do |value|
11p ['y', value]
12end
13parser.on('-z', 'Whether to Z') do |value|
14p ['z', value]
15end
16# Parse the command line and return pared-down ARGV.
17p parser.parse!
18
19$ ruby basic.rb --help
20Usage: basic [options]
21-x Whether to X
22-y Whether to Y
23-z Whether to Z