Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →
class method
Kernel.URI
(::URI::Generic | ::string uri) -> ::URI::Generic
URI(uri)
lib/uri/common.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.4.1/lib/uri/common.rb, line 865
def URI(uri)
if uri.is_a?(URI::Generic)
uri
elsif uri = String.try_convert(uri)
URI.parse(uri)
else
raise ArgumentError,
"bad argument (expected URI object or URI string)"
end
end
Returns a URI object derived from the given uri, which may be a URI string or an existing URI object:
Example
# Returns a new URI. uri = URI('http://github.com/ruby/ruby') # => #<URI::HTTP http://github.com/ruby/ruby> # Returns the given URI. URI(uri) # => #<URI::HTTP http://github.com/ruby/ruby>