summaryrefslogtreecommitdiff
path: root/lib/uri/common.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/uri/common.rb')
-rw-r--r--lib/uri/common.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/uri/common.rb b/lib/uri/common.rb
index e3ed405857..799a268b93 100644
--- a/lib/uri/common.rb
+++ b/lib/uri/common.rb
@@ -146,6 +146,20 @@ module URI
end
#
+ # Construct a URI instance, using the scheme to detect the appropriate class
+ # from +URI.scheme_list+.
+ #
+ def self.for(scheme, *arguments, default: Generic)
+ if scheme
+ uri_class = @@schemes[scheme.upcase] || default
+ else
+ uri_class = default
+ end
+
+ return uri_class.new(scheme, *arguments)
+ end
+
+ #
# Base class for all URI exceptions.
#
class Error < StandardError; end