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

instance method URI::Generic#authority

authority -> [String, String, String, Integer] | nilRuby 4.0 から[permalink][rdoc][edit]

self の authority 情報を [user, password, host, port] という 4 要素の配列で返します。

user・password・host・port のいずれか一つでも設定されていれば配列を返します。設定されていない要素は nil になります。user・password・host・port のいずれも設定されていない場合は nil を返します。

require 'uri'
u = URI('foo://myuser:mypass@www.example.com:8080/bar')
p u.authority # => ["myuser", "mypass", "www.example.com", 8080]

p URI::Generic.build(scheme: 'foo').authority # => nil

[SEE_ALSO] URI::Generic#userinfo, URI::Generic#host, URI::Generic#port