Skip to content

Range object support #80

@kwatch

Description

@kwatch

I hope OptionParser to support Range object such as (1..3) in order to restrict option values.
Currently, OptionParser#on() raises NoMethodError when range object specified.

Example (ex3.rb):

require 'optparse' parser = OptionParser.new parser.on("-x <N>", "int", Integer, (1..3)) #=> NoMethodError #### exception detail # lib/optparse.rb:1509:in `block in make_switch': undefined method `empty?' for an instance of Range (NoMethodError) # # desc.push(o) if o && !o.empty? # ^^^^^^^ #	from lib/optparse.rb:1411:in `each' #	from lib/optparse.rb:1411:in `make_switch' #	from lib/optparse.rb:1541:in `define' #	from lib/optparse.rb:1551:in `on' #	from ex3.rb:4:in `<main>'

Environment:

  • optparse.rb 0.4.0 & 0.5.0
  • Ruby 3.3.5

I can submit a pull request for this issue. Let me know if necessary.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions