Skip to content

Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

URI::Generic#hostname

() -> ::String?
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.3 · 3.2 · 3.1 · 3.0