Skip to content
class method

URI.for

(::String scheme, *untyped arguments, ?default: ::Class) -> (::URI::File | ::URI::FTP | ::URI::HTTP | ::URI::HTTPS | ::URI::LDAP | ::URI::LDAPS | ::URI::MailTo | ::URI::WS | ::URI::WSS | ::URI::Generic)
for(scheme, *arguments, default: Generic)

Returns a new object constructed from the given scheme, arguments, and default:

  • The new object is an instance of URI.scheme_list[scheme.upcase].

  • The object is initialized by calling the class initializer using scheme and arguments. See URI::Generic.new.

Examples:

Example
values = ['john.doe', 'www.example.com', '123', nil, '/forum/questions/', nil, 'tag=networking&order=newest', 'top']
URI.for('https', *values)
# => #<URI::HTTPS https://[email protected]:123/forum/questions/?tag=networking&order=newest#top>
URI.for('foo', *values, default: URI::HTTP)
# => #<URI::HTTP foo://[email protected]:123/forum/questions/?tag=networking&order=newest#top>