Bug #6473
closedEnumerable#count
Description
=begin
Enumerable#count には、
Returns the number of items in enum if it responds to a #size call,
otherwise the items are counted through enumeration. If an argument is
というコメントが書いてありますが、実際には
class E
include Enumerable
def each
end
def size
1
end
end
e = E.new
e.size # => 1
e.count # => 0
size は呼ばれていないようです。1.8 系や 1.9.1 の頃は 0 ではなく 1 が返っていたようです。
=end
Files
Updated by no6v (Nobuhiro IMAI) over 12 years ago
- File enum_count.patch enum_count.patch added
最終的に r25603 で size は呼ばなくなったようなので、コメントを修正したパッチを添付します。
改行位置の関係で行数が多いですが、内容は1文目しか変更してません。
Updated by mame (Yusuke Endoh) over 12 years ago
- Status changed from Open to Assigned
- Assignee set to drbrain (Eric Hodel)
Hello, drbrain
This is a doc issue of Enumerable#count.
Could you check and import Nobuhiro's patch?
English translation:
The rdoc of Enumerable#count says:
Returns the number of items in enum if it responds to a #size call,
otherwise the items are counted through enumeration. If an argument is
but actually it behaves as below:
class E
include Enumerable
def each
end
def size
1
end
end
e = E.new
e.size # => 1
e.count # => 0
As you see, it does not call #size. 1.8 series and 1.9.1 returns 1 instead of 0.
As r25603 seemed to finally decide to stop calling #size, I'm attaching a patch
that changes the rdoc.
The patch just changes the first line, though it looks bigger because of new line.
--
Yusuke Endoh mame@tsg.ne.jp
Updated by drbrain (Eric Hodel) over 12 years ago
- Status changed from Assigned to Closed
- % Done changed from 0 to 100
This issue was solved with changeset r35780.
Nobuhiro, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
- enum.c (enum_count): Enumerable#count no longer uses #size when
counting elements. Patch by Nobuhiro IMAI. [ruby-trunk - Bug #6473]