What is the difference between URI
and URI.parse
? Here is what I get:
require 'uri'
x = "http://google.com"
y = URI(x) # => #<URI::HTTP http://google.com>
z = URI.parse(x) # => #<URI::HTTP http://google.com>
y == z # => true
I see in the docs that a new instance of URI
creates a new URI::Generic
instance from generic components without check, and that it has a default parser in the args.
The general recommendation seems to be URI.parse
, and I am wondering why. I am wondering if there are any gotchas for using URI
and not using URI.parse
. Appreciate any insight.
Related: How to Parse a URL, Parse URL to Get Main Domain, Extract Host from URL string.