From 2408fbfe3ffd67ffe52589b72f244b1de7daf741 Mon Sep 17 00:00:00 2001 From: ksss Date: Fri, 9 Oct 2026 19:01:15 +0900 Subject: [PATCH] Allow block for Data#to_h Co-Authored-By: Claude Opus 5.5 --- core/data.rbs | 1 + test/stdlib/Data_test.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/core/data.rbs b/core/data.rbs index 24edc27f02..d23fd92df6 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 e25241f050..fe4219240a 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