open-uri.rb 689 B

123456789101112131415161718192021
  1. # rubocop:disable Naming/FileName
  2. if Kernel.respond_to?(:open_uri_original_open)
  3. module Kernel
  4. private
  5. # see: https://github.com/ruby/ruby/pull/1675
  6. def open(name, *rest, &block)
  7. if name.respond_to?(:open) && name.method(:open).parameters.present?
  8. name.open(*rest, &block)
  9. elsif name.respond_to?(:to_str) &&
  10. %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ name &&
  11. (uri = URI.parse(name)).respond_to?(:open)
  12. uri.open(*rest, &block)
  13. else
  14. open_uri_original_open(name, *rest, &block)
  15. end
  16. end
  17. module_function :open # rubocop:disable Style/AccessModifierDeclarations
  18. end
  19. end
  20. # rubocop:enable Naming/FileName