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