Skip to content

Commit fdba897

Browse files
euglena1215soutaro
authored andcommitted
stdlib: Accept keyword arguments in Net::HTTP.start
In the original definition, keyword arguments could not be specified without specifying all positional arguments. Specifically, the following call results in an error with `Ruby::ArgumentTypeMismatch`. ```rb Net::HTTP.start('www.ruby-lang.org', 443, use_ssl: true) ``` This is because opt is treated as a hash positional argument. This problem is solved by treating opt as a variable-length keyword argument. ref. https://docs.ruby-lang.org/ja/latest/method/Net=3a=3aHTTP/s/start.html
1 parent a39cabf commit fdba897

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

stdlib/net-http/0/net-http.rbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -978,8 +978,8 @@ module Net
978978
# Note: If `port` is `nil` and `opts[:use_ssl]` is a truthy value, the value
979979
# passed to `new` is Net::HTTP.https_default_port, not `port`.
980980
#
981-
def self.start: (String address, ?Integer? port, ?String | :ENV | nil p_addr, ?Integer? p_port, ?String? p_user, ?String? p_pass, ?Hash[Symbol, untyped]? opt) -> Net::HTTP
982-
| [T] (String address, ?Integer? port, ?String | :ENV | nil p_addr, ?Integer? p_port, ?String? p_user, ?String? p_pass, ?Hash[Symbol, untyped]? opt) { (Net::HTTP) -> T } -> T
981+
def self.start: (String address, ?Integer? port, ?String | :ENV | nil p_addr, ?Integer? p_port, ?String? p_user, ?String? p_pass, **untyped opt) -> Net::HTTP
982+
| [T] (String address, ?Integer? port, ?String | :ENV | nil p_addr, ?Integer? p_port, ?String? p_user, ?String? p_pass, **untyped opt) { (Net::HTTP) -> T } -> T
983983

984984
# <!--
985985
# rdoc-file=lib/net/http.rb

test/stdlib/Net_HTTP_test.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ def test_new
5151
assert_send_type "(String, Integer, nil, nil, nil, nil, nil) -> Net::HTTP",
5252
Net::HTTP, :new, 'www.ruby-lang.org', 80, nil, nil, nil, nil, nil
5353
end
54+
55+
def test_start
56+
assert_send_type "(String, Integer) -> Net::HTTP",
57+
Net::HTTP, :start, 'www.ruby-lang.org', 80
58+
assert_send_type "(String, Integer, use_ssl: bool) -> Net::HTTP",
59+
Net::HTTP, :start, 'www.ruby-lang.org', 443, use_ssl: true
60+
assert_send_type "(String, Integer) { (Net::HTTP) -> untyped } -> untyped",
61+
Net::HTTP, :start, 'www.ruby-lang.org', 80 do |net_http| net_http.class end
62+
assert_send_type "(String, Integer, use_ssl: bool) { (Net::HTTP) -> untyped } -> untyped",
63+
Net::HTTP, :start, 'www.ruby-lang.org', 443, use_ssl: true do |net_http| net_http.class end
64+
end
5465
end
5566

5667
class NetInstanceTest < Test::Unit::TestCase

0 commit comments

Comments
 (0)