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)
lib/uri/common.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.0.0/lib/uri/common.rb, line 187
def self.for(scheme, *arguments, default: Generic)
const_name = Schemes.escape(scheme)
uri_class = INITIAL_SCHEMES[const_name]
uri_class ||= Schemes.find(const_name)
uri_class ||= default
return uri_class.new(scheme, *arguments)
end
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
schemeandarguments. SeeURI::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>
See also
.encode_www_form_component
.join
.encode_www_form
.open
also in
4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0