diff options
author | Hiroshi SHIBATA <[email protected]> | 2024-01-16 16:30:32 +0900 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2024-01-16 17:07:10 +0900 |
commit | 4b6936aa047158c98a9ac8861d51e5e09229f8c0 (patch) | |
tree | 9dca3595126af7fd634d7d9bf15c7d4811196082 /sample | |
parent | 3f5016178cb81536e800a9121b3804e36c9af93c (diff) |
Unbundled samples for getoptlong
Diffstat (limited to 'sample')
-rw-r--r-- | sample/getoptlong/abbrev.rb | 9 | ||||
-rw-r--r-- | sample/getoptlong/aliases.rb | 8 | ||||
-rw-r--r-- | sample/getoptlong/argv.rb | 12 | ||||
-rw-r--r-- | sample/getoptlong/each.rb | 12 | ||||
-rw-r--r-- | sample/getoptlong/fibonacci.rb | 62 | ||||
-rw-r--r-- | sample/getoptlong/permute.rb | 12 | ||||
-rw-r--r-- | sample/getoptlong/require_order.rb | 13 | ||||
-rw-r--r-- | sample/getoptlong/return_in_order.rb | 13 | ||||
-rw-r--r-- | sample/getoptlong/simple.rb | 7 | ||||
-rw-r--r-- | sample/getoptlong/types.rb | 10 |
10 files changed, 0 insertions, 158 deletions
diff --git a/sample/getoptlong/abbrev.rb b/sample/getoptlong/abbrev.rb deleted file mode 100644 index 9b89863626..0000000000 --- a/sample/getoptlong/abbrev.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'getoptlong' - -options = GetoptLong.new( - ['--xxx', GetoptLong::NO_ARGUMENT], - ['--xyz', GetoptLong::NO_ARGUMENT] -) -options.each do |option, argument| - p [option, argument] -end diff --git a/sample/getoptlong/aliases.rb b/sample/getoptlong/aliases.rb deleted file mode 100644 index 895254c6ae..0000000000 --- a/sample/getoptlong/aliases.rb +++ /dev/null @@ -1,8 +0,0 @@ -require 'getoptlong' - -options = GetoptLong.new( - ['--xxx', '-x', '--aaa', '-a', '-p', GetoptLong::NO_ARGUMENT] -) -options.each do |option, argument| - p [option, argument] -end diff --git a/sample/getoptlong/argv.rb b/sample/getoptlong/argv.rb deleted file mode 100644 index 8efcad22ea..0000000000 --- a/sample/getoptlong/argv.rb +++ /dev/null @@ -1,12 +0,0 @@ -require 'getoptlong' - -options = GetoptLong.new( - ['--xxx', GetoptLong::REQUIRED_ARGUMENT], - ['--yyy', GetoptLong::OPTIONAL_ARGUMENT], - ['--zzz', GetoptLong::NO_ARGUMENT] -) -puts "Original ARGV: #{ARGV}" -options.each do |option, argument| - p [option, argument] -end -puts "Remaining ARGV: #{ARGV}" diff --git a/sample/getoptlong/each.rb b/sample/getoptlong/each.rb deleted file mode 100644 index 661e0a968f..0000000000 --- a/sample/getoptlong/each.rb +++ /dev/null @@ -1,12 +0,0 @@ -require 'getoptlong' - -options = GetoptLong.new( - ['--xxx', '-x', GetoptLong::REQUIRED_ARGUMENT], - ['--yyy', '-y', GetoptLong::OPTIONAL_ARGUMENT], - ['--zzz', '-z',GetoptLong::NO_ARGUMENT] -) -puts "Original ARGV: #{ARGV}" -options.each do |option, argument| - p [option, argument] -end -puts "Remaining ARGV: #{ARGV}" diff --git a/sample/getoptlong/fibonacci.rb b/sample/getoptlong/fibonacci.rb deleted file mode 100644 index 24a2aab3c3..0000000000 --- a/sample/getoptlong/fibonacci.rb +++ /dev/null @@ -1,62 +0,0 @@ -require 'getoptlong' - -options = GetoptLong.new( - ['--number', '-n', GetoptLong::REQUIRED_ARGUMENT], - ['--verbose', '-v', GetoptLong::OPTIONAL_ARGUMENT], - ['--help', '-h', GetoptLong::NO_ARGUMENT] -) - -def help(status = 0) - puts <<~HELP - Usage: - - -n n, --number n: - Compute Fibonacci number for n. - -v [boolean], --verbose [boolean]: - Show intermediate results; default is 'false'. - -h, --help: - Show this help. - HELP - exit(status) -end - -def print_fibonacci (number) - return 0 if number == 0 - return 1 if number == 1 or number == 2 - i = 0 - j = 1 - (2..number).each do - k = i + j - i = j - j = k - puts j if @verbose - end - puts j unless @verbose -end - -options.each do |option, argument| - case option - when '--number' - @number = argument.to_i - when '--verbose' - @verbose = if argument.empty? - true - elsif argument.match(/true/i) - true - elsif argument.match(/false/i) - false - else - puts '--verbose argument must be true or false' - help(255) - end - when '--help' - help - end -end - -unless @number - puts 'Option --number is required.' - help(255) -end - -print_fibonacci(@number) diff --git a/sample/getoptlong/permute.rb b/sample/getoptlong/permute.rb deleted file mode 100644 index 8efcad22ea..0000000000 --- a/sample/getoptlong/permute.rb +++ /dev/null @@ -1,12 +0,0 @@ -require 'getoptlong' - -options = GetoptLong.new( - ['--xxx', GetoptLong::REQUIRED_ARGUMENT], - ['--yyy', GetoptLong::OPTIONAL_ARGUMENT], - ['--zzz', GetoptLong::NO_ARGUMENT] -) -puts "Original ARGV: #{ARGV}" -options.each do |option, argument| - p [option, argument] -end -puts "Remaining ARGV: #{ARGV}" diff --git a/sample/getoptlong/require_order.rb b/sample/getoptlong/require_order.rb deleted file mode 100644 index 357f667905..0000000000 --- a/sample/getoptlong/require_order.rb +++ /dev/null @@ -1,13 +0,0 @@ -require 'getoptlong' - -options = GetoptLong.new( - ['--xxx', GetoptLong::REQUIRED_ARGUMENT], - ['--yyy', GetoptLong::OPTIONAL_ARGUMENT], - ['--zzz', GetoptLong::NO_ARGUMENT] -) -options.ordering = GetoptLong::REQUIRE_ORDER -puts "Original ARGV: #{ARGV}" -options.each do |option, argument| - p [option, argument] -end -puts "Remaining ARGV: #{ARGV}" diff --git a/sample/getoptlong/return_in_order.rb b/sample/getoptlong/return_in_order.rb deleted file mode 100644 index 91ce1ef996..0000000000 --- a/sample/getoptlong/return_in_order.rb +++ /dev/null @@ -1,13 +0,0 @@ -require 'getoptlong' - -options = GetoptLong.new( - ['--xxx', GetoptLong::REQUIRED_ARGUMENT], - ['--yyy', GetoptLong::OPTIONAL_ARGUMENT], - ['--zzz', GetoptLong::NO_ARGUMENT] -) -options.ordering = GetoptLong::RETURN_IN_ORDER -puts "Original ARGV: #{ARGV}" -options.each do |option, argument| - p [option, argument] -end -puts "Remaining ARGV: #{ARGV}" diff --git a/sample/getoptlong/simple.rb b/sample/getoptlong/simple.rb deleted file mode 100644 index 1af6447632..0000000000 --- a/sample/getoptlong/simple.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'getoptlong' - -options = GetoptLong.new( - ['--number', '-n', GetoptLong::REQUIRED_ARGUMENT], - ['--verbose', '-v', GetoptLong::OPTIONAL_ARGUMENT], - ['--help', '-h', GetoptLong::NO_ARGUMENT] -) diff --git a/sample/getoptlong/types.rb b/sample/getoptlong/types.rb deleted file mode 100644 index ac74bfe12e..0000000000 --- a/sample/getoptlong/types.rb +++ /dev/null @@ -1,10 +0,0 @@ -require 'getoptlong' - -options = GetoptLong.new( - ['--xxx', GetoptLong::REQUIRED_ARGUMENT], - ['--yyy', GetoptLong::OPTIONAL_ARGUMENT], - ['--zzz', GetoptLong::NO_ARGUMENT] -) -options.each do |option, argument| - p [option, argument] -end |