Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

class method

URI.for

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>