diff --git a/core/data.rbs b/core/data.rbs index 24edc27f0..d23fd92df 100644 --- a/core/data.rbs +++ b/core/data.rbs @@ -367,6 +367,7 @@ class Data # #=> true # def to_h: () -> Hash[Symbol, untyped] + | [K, V] () { (Symbol key, untyped value) -> [K, V] } -> Hash[K, V] # # Returns a string representation of `self`: diff --git a/test/stdlib/Data_test.rb b/test/stdlib/Data_test.rb index e25241f05..fe4219240 100644 --- a/test/stdlib/Data_test.rb +++ b/test/stdlib/Data_test.rb @@ -40,4 +40,17 @@ def test_with data, :with, email: "test@example.com" ) end + + def test_to_h + data = D.new("soutaro@example.com", "soutaro") + + assert_send_type( + "() -> Hash[Symbol, untyped]", + data, :to_h + ) + assert_send_type( + "() { (Symbol, untyped) -> [String, String] } -> Hash[String, String]", + data, :to_h, &-> (key, value) { [key.to_s, value.to_s] } + ) + end end