Skip to content

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

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]"
See also #hostname= #host= #hierarchical? #inspect also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1