このマニュアルは既にメンテナンスが終了したバージョンの Ruby を対象としています。 最新版のマニュアルへ

Ruby 3.1 リファレンスマニュアル

instance method URI::Generic#coerce

coerce(oth) -> [URI, URI]Ruby 2.0.0 から[permalink][rdoc][edit]

引数 oth をパースして [パース後の oth, self] の配列を返します。

[PARAM] oth:
URI オブジェクトか文字列を指定します。
require 'uri'

uri = URI.parse("http://my.example.com")
p uri.coerce("http://foo.com")
# => [#<URI::HTTP:0x00000000bcb028 URL:http://foo.com/>, #<URI::HTTP:0x00000000d92178 URL:http://my.example.com>]