From: "luke-gru (Luke Gruber) via ruby-core" Date: 2023-04-03T15:04:09+00:00 Subject: [ruby-core:113084] [Ruby master Bug#19566] OptionParser::on raises unsupported argument type: URI (ArgumentError) but shouldn't Issue #19566 has been updated by luke-gru (Luke Gruber). You need to `require optparse/uri`. The docs should probably mention that if they don't already. ---------------------------------------- Bug #19566: OptionParser::on raises unsupported argument type: URI (ArgumentError) but shouldn't https://bugs.ruby-lang.org/issues/19566#change-102619 * Author: jgomo3 (Jes��s G��mez) * Status: Open * Priority: Normal * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- 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-workaround.rb (377 Bytes) -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/