Skip to content

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

class method

URI.parse

parse(uri)

Synopsis

Example
URI::parse(uri_str)

Args

uri_str

String with URI.

Description

Creates one of the URI’s subclasses instance from the string.

Raises

URI::InvalidURIError

Raised if URI given is not a correct one.

Usage

Example
require 'uri'

uri = URI.parse("http://www.ruby-lang.org/")
# => #<URI::HTTP http://www.ruby-lang.org/>
uri.scheme
# => "http"
uri.host
# => "www.ruby-lang.org"

It’s recommended to first ::escape the provided uri_str if there are any invalid URI characters.

See also .open .regexp .join .scheme_list also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1