diff options
author | Samuel Williams <[email protected]> | 2019-12-28 11:36:41 +1300 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2020-03-26 18:06:14 +0900 |
commit | 844ff7ea45b79e95eaed4b725fd0cf5c33874058 (patch) | |
tree | 37dea6e0b7169683d8ee5509f3acac2dbfc08f3c /lib/uri/common.rb | |
parent | e460c2d033b1e7a95417aa93cb4a3cd5cf57b25c (diff) |
[ruby/uri] Simplify construction of URI instances using parser interface.
https://github.com/ruby/uri/commit/c145017dd7
Diffstat (limited to 'lib/uri/common.rb')
-rw-r--r-- | lib/uri/common.rb | 14 |
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 |