Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A few small fixes for rubyspecs #192

Merged
merged 6 commits into from
Mar 5, 2024
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions lib/backports/3.2.0/enumerator/product.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
unless Enumerator.method_defined? :product
if RUBY_VERSION >= '2.7'
instance_eval <<-EOT, __FILE__, __LINE__ + 1
def Enumerator.product(*enums, **nil, &block)
instance_eval <<-'EOT', __FILE__, __LINE__ + 1
def Enumerator.product(*enums, **kwargs, &block)
if kwargs && !kwargs.empty?
raise ArgumentError, "unknown keywords: #{kwargs.keys.map(&:inspect).join(", ")}"
marcandre marked this conversation as resolved.
Show resolved Hide resolved
end
Enumerator::Product.new(*enums).each(&block)
end
EOT
else
def Enumerator.product(*enums, &block)
kwargs = enums[-1]
if kwargs.is_a?(Hash) && !kwargs.empty?
raise ArgumentError, "unknown keywords: #{kwargs.keys.map(&:inspect).join(", ")}"
marcandre marked this conversation as resolved.
Show resolved Hide resolved
end
Enumerator::Product.new(*enums).each(&block)
end
end
Expand Down Expand Up @@ -47,15 +54,17 @@ def __execute(block, values, enums)
def size
total_size = 1
@__enums.each do |enum|
return nil unless enum.respond_to?(:size)
size = enum.size
return size if size == nil || size == Float::INFINITY
return nil unless size.is_a?(Integer)
total_size *= size
end
total_size
end

def rewind
@__enums.reverse_each do |enum|
@__enums.each do |enum|
enum.rewind if enum.respond_to?(:rewind)
end
self
Expand Down
Loading