On this page
End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
URI::Generic
Class methods 5
Instance methods 61
An Array of the available components for URI::Generic.
A Default port of nil for URI::Generic.
Returns the fragment component of the URI.
URI("http://foo/bar/baz?search=FooBar#ponies").fragment #=> "ponies"
Returns the host component of the URI.
URI("http://foo/bar/baz").host #=> "foo"
It returns nil if no host component exists.
URI("mailto:[email protected]").host #=> nil
The component does not contain the port number.
URI("http://foo:8080/bar/baz").host #=> "foo"
Since IPv6 addresses are wrapped with brackets in URIs, this method returns IPv6 addresses wrapped with brackets. This form is not appropriate to pass to socket methods such as TCPSocket.open. If unwrapped host names are required, use the hostname method.
URI("http://[::1]/bar/baz").host #=> "[::1]" URI("http://[::1]/bar/baz").hostname #=> "::1"
Returns the opaque part of the URI.
URI("mailto:[email protected]").opaque #=> "[email protected]" URI("http://foo/bar/baz").opaque #=> nil
The portion of the path that does not make use of the slash ‘/’. The path typically refers to an absolute path or an opaque part. (See RFC2396 Section 3 and 5.2.)
Returns the port component of the URI.
URI("http://foo/bar/baz").port #=> 80 URI("http://foo:8080/bar/baz").port #=> 8080
Returns the query component of the URI.
URI("http://foo/bar/baz?search=FooBar").query #=> "search=FooBar"