From da2b608e3b07fae315fad21d5969fcd33eea40cd Mon Sep 17 00:00:00 2001 From: Oskar Eichler Date: Fri, 28 Aug 2026 03:04:15 +0300 Subject: [PATCH 1/2] Enumerate the original method through bang aliases aliases --- lib/ostruct.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ostruct.rb b/lib/ostruct.rb index a8763da..5e78e65 100644 --- a/lib/ostruct.rb +++ b/lib/ostruct.rb @@ -209,7 +209,7 @@ def to_h(&block) # data.each_pair.to_a # => [[:country, "Australia"], [:capital, "Canberra"]] # def each_pair - return to_enum(__method__) { @table.size } unless defined?(yield) + return to_enum!(__callee__) { @table.size } unless defined?(yield) @table.each_pair{|p| yield p} self end From 63d31199e4538d6f6f6732d90fd6f8a3e24d66ca Mon Sep 17 00:00:00 2001 From: Oskar Eichler <62393985+OskarEichler@users.noreply.github.com> Date: Fri, 28 Aug 2026 14:56:20 +0300 Subject: [PATCH 2/2] test: cover OpenStruct field collision regression --- test/ostruct/test_ostruct.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/ostruct/test_ostruct.rb b/test/ostruct/test_ostruct.rb index 616f84d..56226b5 100644 --- a/test/ostruct/test_ostruct.rb +++ b/test/ostruct/test_ostruct.rb @@ -439,4 +439,12 @@ def test_performance_warning ) end end + def test_each_pair_alias_with_colliding_fields + o = OpenStruct.new(to_enum: 7, other: 4) + assert_equal([[:to_enum, 7], [:other, 4]], o.each_pair!.to_a) + + o = OpenStruct.new(each_pair: 7, other: 4) + assert_equal([[:each_pair, 7], [:other, 4]], o.each_pair!.to_a) + end + end