Class: OXO::Optionparser
- Inherits:
-
Object
- Object
- OXO::Optionparser
- Defined in:
- lib/oxo.rb
Class Method Summary collapse
-
.parse!(argv) ⇒ Object
Parses the command line options from
argv.
Class Method Details
.parse!(argv) ⇒ Object
Parses the command line options from argv. (argv is cleared). Might print out help or version information.
argv - array with the command line options
Returns a hash containing the option parameters.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/oxo.rb', line 48 def self.parse!(argv) = { delay: 0 } opt_parser = OptionParser.new do |opt| opt. = "Usage: #{PROGNAME} [options]" opt.separator "\n oxo is a command line Tic-tac-toe game.\n\n Options:\n CONTENT\n\n # process --version and --help first,\n # exit successfully (GNU Coding Standards)\n opt.on_tail(\"-h\", \"--help\", \"Print a brief help message and exit.\") do\n puts opt_parser\n puts \"\\nReport bugs on the \#{PROGNAME} home page: <\#{HOMEPAGE}>\"\n exit\n end\n\n opt.on_tail(\"-v\", \"--version\",\n \"Print a brief version information and exit.\") do\n puts \"\#{PROGNAME} \#{VERSION}\"\n puts COPYRIGHT\n exit\n end\n\n opt.on(\"-d\", \"--delay SECONDS\", Float,\n \"Set delay time for oxo's moves.\") do |d|\n options[:delay] = d\n end\n\n opt.separator \"\"\n end\n opt_parser.parse!(argv)\n\n # nothing should be left in argv\n raise(ArgumentError, \"wrong number of arguments\") unless argv.empty?\n\n options\nend\n" |