Skip to content
On this page

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

class · Ruby 3.0

URI::Generic

< Object include URI 61 instance methods 5 class methods

Base class for all URI classes. Implements generic URI syntax as per RFC 2396.

Class methods 5

Instance methods 61

Constants

An Array of the available components for URI::Generic.

A Default port of nil for URI::Generic.

No documentation available
Attributes
Read

Returns the fragment component of the URI.

Example
URI("http://foo/bar/baz?search=FooBar#ponies").fragment #=> "ponies"
Read

Returns the host component of the URI.

Example
URI("http://foo/bar/baz").host #=> "foo"

It returns nil if no host component exists.

Example
URI("mailto:[email protected]").host #=> nil

The component does not contain the port number.

Example
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.

Example
URI("http://[::1]/bar/baz").host     #=> "[::1]"
URI("http://[::1]/bar/baz").hostname #=> "::1"
Read

Returns the opaque part of the URI.

Example
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.)

Read

Returns the path component of the URI.

Example
URI("http://foo/bar/baz").path #=> "/bar/baz"
Read

Returns the port component of the URI.

Example
URI("http://foo/bar/baz").port      #=> 80
URI("http://foo:8080/bar/baz").port #=> 8080
Read

Returns the query component of the URI.

Example
URI("http://foo/bar/baz?search=FooBar").query #=> "search=FooBar"
Read

Returns the scheme component of the URI.

Example
URI("http://foo/bar/baz").scheme #=> "http"