[ruby-core:73552] [Ruby trunk - Bug #12029] Not all elements are yielded when count is given a block

From: jasonyeo88@...
Date: 2016-01-28 12:44:31 UTC
List: ruby-core #73552
Issue #12029 has been updated by Jason Yeo.


Hans Mackowiak wrote:
> you need splash:
> 
> ```ruby
> 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?

----------------------------------------
Bug #12029: Not all elements are yielded when count is given a block
https://bugs.ruby-lang.org/issues/12029#change-56762

* Author: Jason Yeo
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 2.3.0
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
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
~~~




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next