Project

General

Profile

Actions

Bug #12029

closed

Not all elements are yielded when count is given a block

Added by jsyeo (Jason Yeo) over 8 years ago. Updated over 8 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:73550]

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
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0