instance method
URI::Generic#hostname
() -> ::String?
hostname
lib/uri/generic.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.0.0/lib/uri/generic.rb, line 668
def hostname
v = self.host
v&.start_with?('[') && v.end_with?(']') ? v[1..-2] : 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]"