From b0eea13dd1d0b09c3dd8b80f8019fca6a577f715 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Mon, 14 Oct 2024 16:41:16 -0500 Subject: [PATCH] Get most Enumerator::Product specs passing Remaining specs are for #inspect which is not yet implemented. See https://github.com/marcandre/backports/issues/194 --- core/src/main/ruby/jruby/kernel/enumerator.rb | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/core/src/main/ruby/jruby/kernel/enumerator.rb b/core/src/main/ruby/jruby/kernel/enumerator.rb index 3ba602c3564..b5bf63079ac 100644 --- a/core/src/main/ruby/jruby/kernel/enumerator.rb +++ b/core/src/main/ruby/jruby/kernel/enumerator.rb @@ -487,11 +487,14 @@ def Enumerator.product(*enums, **kwargs, &block) class Enumerator::Product < Enumerator def initialize(*enums, **nil) @__enums = enums + self end def each(&block) - return self unless block - __execute(block, [], @__enums) + if block + __execute(block, [], @__enums) + end + self end def __execute(block, values, enums) @@ -525,4 +528,20 @@ def rewind end self end + + private def initialize_copy(other) + return self if self.equal?(other) + + raise TypeError if !(Product === other) + + super(other) + + other_enums = other.instance_variable_get(:@__enums) + + raise ArgumentError.new("uninitialized product") unless other_enums + + @__enums = other_enums + + self + end end