diff --git a/lib/core_ext/open-uri.rb b/lib/core_ext/open-uri.rb new file mode 100644 index 000000000..703b20594 --- /dev/null +++ b/lib/core_ext/open-uri.rb @@ -0,0 +1,20 @@ +# rubocop:disable Style/FileName +if Kernel.respond_to?(:open_uri_original_open) + module Kernel + private + + # see: https://github.com/ruby/ruby/pull/1675 + def open(name, *rest, &block) # :doc: + if name.respond_to?(:open) && !name.method(:open).parameters.empty? + name.open(*rest, &block) + elsif name.respond_to?(:to_str) && + %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ name && + (uri = URI.parse(name)).respond_to?(:open) + uri.open(*rest, &block) + else + open_uri_original_open(name, *rest, &block) + end + end + module_function :open + end +end