Actions
Bug #12029
closedNot all elements are yielded when count is given a block
Description
When count is called on an enumerable that yields multiple elements, not all elements are yielded to the block.
def foo
yield 1, 2
end
to_enum(:foo).count { |e| e == [1, 2] }
# Returns: 0
# Expected: 1
It appears that only the first element is yielded:
to_enum(:foo).count { |e| p e; e == [1, 2] }
# Prints 1
Updated by Hanmac (Hans Mackowiak) about 8 years ago
you need splash:
to_enum(:foo).count { |*e| e == [1, 2] } #=> 1
Updated by jsyeo (Jason Yeo) about 8 years ago
Hans Mackowiak wrote:
you need splash:
to_enum(:foo).count { |*e| e == [1, 2] } #=> 1
hmmm, okay. I think I misunderstood how some Enumerable methods work. Thanks.
How do I close this issue by the way?
Updated by nobu (Nobuyoshi Nakada) about 8 years ago
- Description updated (diff)
- Status changed from Open to Rejected
Actions
Like0
Like0Like0Like0