Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Gem::Command#add_option
add_option(*opts) { |value, options| ... }
lib/rubygems/command.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/lib/rubygems/command.rb, line 358
def add_option(*opts, &handler) # :yields: value, options
group_name = Symbol === opts.first ? opts.shift : :options
raise "Do not pass an empty string in opts" if opts.include?("")
@option_groups[group_name] << [opts, handler]
end
Add a command-line option and handler to the command.
See Gem::OptionParser#make_switch for an explanation of opts.
handler will be called with two values, the value of the argument and the options hash.
If the first argument of add_option is a Symbol, it’s used to group options in output. See ‘gem help list` for an example.
See also
#add_extra_args
#add_parser_run_info
.specific_extra_args_hash
#arguments
also in
4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0