End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
URI::Generic#hostname
hostname
lib/uri/generic.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.0.5/lib/uri/generic.rb, line 644
def hostname
v = self.host
/\A\[(.*)\]\z/ =~ v ? $1 : v
end
Extract the host part of the URI and unwrap brackets for IPv6 addresses.
This method is the same as URI::Generic#host except brackets for IPv6 (and future IP) addresses are removed.
Example
uri = URI("http://[::1]/bar") uri.hostname #=> "::1" uri.host #=> "[::1]"