diff options
author | Burdette Lamar <BurdetteLamar@Yahoo.com> | 2021-04-10 16:30:19 -0500 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2021-04-11 08:52:54 +0900 |
commit | 1bad4bdf524fc07be8ece1dc784fdbedc07d8a97 (patch) | |
tree | 80948d35713f8ab4a27ea0d7d57eb0ba7e0e03f9 /doc/ruby/missing_options.rb | |
parent | ff0dac184902e42fac148940cd6c026679a0ee21 (diff) |
[ruby/optparse] More on tutorial (#16)
- Added example in "Argument Converters"; it doesn't seem right for a tutorial to have no example in one of its topics (and instead just linking elsewhere).
- Added section "Command-Line Abbreviations."
- Added section "Keyword Argument into," showing how to:
- Collect options.
- Check for missing options.
- Provide option defaults.
https://github.com/ruby/optparse/commit/39d39676c4
Diffstat (limited to 'doc/ruby/missing_options.rb')
-rw-r--r-- | doc/ruby/missing_options.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/doc/ruby/missing_options.rb b/doc/ruby/missing_options.rb new file mode 100644 index 0000000000..9428463cfd --- /dev/null +++ b/doc/ruby/missing_options.rb @@ -0,0 +1,12 @@ +require 'optparse' +parser = OptionParser.new +parser.on('-x', '--xxx', 'Short and long, no argument') +parser.on('-yYYY', '--yyy', 'Short and long, required argument') +parser.on('-z [ZZZ]', '--zzz', 'Short and long, optional argument') +options = {} +parser.parse!(into: options) +required_options = [:xxx, :zzz] +missing_options = required_options - options.keys +unless missing_options.empty? + fail "Missing required options: #{missing_options}" +end |