[#45637] [ruby-trunk - Feature #6440][Open] 引数にIOを渡した場合のMarshal.loadにバッファを持たせたい — "Glass_saga (Masaki Matsushita)" <glass.saga@...>

14 messages 2012/05/16

[#45670] [ruby-trunk - Bug #6479][Open] ipaddr.rbの受け付ける書式が、プラットフォームによって異なる — "kachick (Kenichi Kamiya)" <kachick1+ruby@...>

9 messages 2012/05/22

[ruby-dev:45661] [ruby-trunk - Bug #6473][Assigned] Enumerable#count

From: "mame (Yusuke Endoh)" <mame@...>
Date: 2012-05-21 10:24:03 UTC
List: ruby-dev #45661
Issue #6473 has been updated by mame (Yusuke Endoh).

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 <i>enum</i> 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>
----------------------------------------
Bug #6473: Enumerable#count
https://bugs.ruby-lang.org/issues/6473#change-26736

Author: no6v (Nobuhiro IMAI)
Status: Assigned
Priority: Normal
Assignee: drbrain (Eric Hodel)
Category: core
Target version: 
ruby -v: ruby 2.0.0dev (2012-05-19 trunk 35705) [x86_64-linux]


=begin
Enumerable#count には、

 Returns the number of items in <i>enum</i> 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



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

In This Thread

Prev Next