Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

class method

URI.parse

(::_ToStr uri) -> (::URI::File | ::URI::FTP | ::URI::HTTP | ::URI::HTTPS | ::URI::LDAP | ::URI::LDAPS | ::URI::MailTo | ::URI::WS | ::URI::WSS | ::URI::Generic)
parse(uri)

Returns a new URI object constructed from the given string uri:

Example
URI.parse('https://[email protected]:123/forum/questions/?tag=networking&order=newest#top')
# => #<URI::HTTPS https://[email protected]:123/forum/questions/?tag=networking&order=newest#top>
URI.parse('http://[email protected]:123/forum/questions/?tag=networking&order=newest#top')
# => #<URI::HTTP http://[email protected]:123/forum/questions/?tag=networking&order=newest#top>

It’s recommended to first URI::RFC2396_PARSER.escape string uri if it may contain invalid URI characters.

See also .open .parser= .join .register_scheme also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0