Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
GetoptLong#each
each() { |option_name, option_argument| ... }
lib/getoptlong.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.3.0/lib/getoptlong.rb, line 859
def each
loop do
option_name, option_argument = get_option
break if option_name == nil
yield option_name, option_argument
end
end
Calls the given block with each option; each option is a 2-element array containing:
-
The option name (the name itself, not an alias).
-
The option value.
Example:
Example
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}"
Command line:
ruby each.rb -xxx Foo -x Bar --yyy Baz -y Bat --zzz
Output:
Example
Original ARGV: ["-xxx", "Foo", "-x", "Bar", "--yyy", "Baz", "-y", "Bat", "--zzz"] ["--xxx", "xx"] ["--xxx", "Bar"] ["--yyy", "Baz"] ["--yyy", "Bat"] ["--zzz", ""] Remaining ARGV: ["Foo"]