Skip to content

End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

class method

GetoptLong.new

new(*arguments)

Returns a new GetoptLong object based on the given arguments. See Options.

Example:

Example
require 'getoptlong'

options = GetoptLong.new(
  ['--number', '-n', GetoptLong::REQUIRED_ARGUMENT],
  ['--verbose', '-v', GetoptLong::OPTIONAL_ARGUMENT],
  ['--help', '-h', GetoptLong::NO_ARGUMENT]
)

Raises an exception if:

  • Any of arguments is not an array.

  • Any option name or alias is not a string.

  • Any option type is invalid.

See also #each #each_option also in 3.3 · 3.1 · 3.0