Skip to content

Commit

Permalink
Get most Enumerator::Product specs passing
Browse files Browse the repository at this point in the history
Remaining specs are for #inspect which is not yet implemented.

See marcandre/backports#194
  • Loading branch information
headius committed Oct 14, 2024
1 parent 9d4d157 commit b0eea13
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions core/src/main/ruby/jruby/kernel/enumerator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

0 comments on commit b0eea13

Please sign in to comment.