open-uri.rb 611 B

1234567891011121314151617181920
  1. # rubocop:disable Style/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) # :doc:
  7. if name.respond_to?(:open) && !name.method(:open).parameters.empty?
  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
  18. end
  19. end