Project

General

Profile

Actions

Bug #19566

closed

OptionParser::on raises unsupported argument type: URI (ArgumentError) but shouldn't

Added by jgomo3 (Jesús Gómez) over 1 year ago. Updated over 1 year ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:113064]

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

ruby-op-uri-bug.rb (340 Bytes) ruby-op-uri-bug.rb jgomo3 (Jesús Gómez), 03/31/2023 10:56 PM
ruby-op-uri-bug-workaround.rb (377 Bytes) ruby-op-uri-bug-workaround.rb jgomo3 (Jesús Gómez), 03/31/2023 10:56 PM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0