Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. 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.2 · 3.1 · 3.0