Bug #19566
closedOptionParser::on raises unsupported argument type: URI (ArgumentError) but shouldn't
Description
The documentation says
OptionParser comes with a few ready-to-use kinds of type coercion. They are
..
- URI – Anything accepted by URI.parse
But when I try to use the class URI as a coercion class:
op = OptionParser.new
op.on("--uri URI", URI)
I get: unsupported argument type: URI (ArgumentError).
The workaround is to register it with accept:
op = OptionParser.new
op.accept(URI, &URI.method(:parse))
op.on("--uri URI", URI)
I attached 2 files, the first one ruby-op-uri-bug.rb displays the Error.
The second one, ruby-op-uri-workaround.rb show the proper output.
Files
        
           Updated by luke-gru (Luke Gruber) over 2 years ago
          Updated by luke-gru (Luke Gruber) over 2 years ago
          
          
        
        
      
      You need to require "optparse/uri". The docs should probably mention that if they don't already.
        
           Updated by jeremyevans0 (Jeremy Evans) over 2 years ago
          Updated by jeremyevans0 (Jeremy Evans) over 2 years ago
          
          
        
        
      
      I submitted a pull request to document the requires needed, not just for URI, but for Date/DateTime/Time/Shellwords as well: https://github.com/ruby/optparse/pull/54
        
           Updated by jeremyevans (Jeremy Evans) over 2 years ago
          Updated by jeremyevans (Jeremy Evans) over 2 years ago
          
          
        
        
      
      - Status changed from Open to Closed
Applied in changeset git|bb927acd3bd3a5a5797587bc4201724235ed26b5.
[ruby/optparse] Document requires needed for Date/DateTime/Time/URI/Shellwords support
Fixes [Bug #19566]