diff --git a/lib/open-uri.rb b/lib/open-uri.rb index 0052bb49fb..11af0f7a12 100644 --- a/lib/open-uri.rb +++ b/lib/open-uri.rb @@ -31,6 +31,7 @@ module URI super end end + singleton_class.send(:ruby2_keywords, :open) if respond_to?(:ruby2_keywords, true) end # OpenURI is an easy-to-use wrapper for Net::HTTP, Net::HTTPS and Net::FTP. diff --git a/test/open-uri/test_open-uri.rb b/test/open-uri/test_open-uri.rb index fdd1969666..8c8f75ce03 100644 --- a/test/open-uri/test_open-uri.rb +++ b/test/open-uri/test_open-uri.rb @@ -172,6 +172,16 @@ class TestOpenURI < Test::Unit::TestCase assert_raise(ArgumentError) { URI.open("http://127.0.0.1/", :invalid_option=>true) {} } end + def test_pass_keywords + require 'tempfile' + t = Tempfile.new + assert_kind_of File, URI.open(Tempfile.new.path, mode: 0666) + + o = Object.new + def o.open(foo: ) foo end + assert_equal 1, URI.open(o, foo: 1) + end + def test_mode with_http {|srv, dr, url| srv.mount_proc("/mode", lambda { |req, res| res.body = "mode" } )