From: "marcandre (Marc-Andre Lafortune)" Date: 2013-07-17T22:51:33+09:00 Subject: [ruby-core:56064] [ruby-trunk - Bug #8641] Enumerator size argument is either mis-documented or should accept any callable Issue #8641 has been updated by marcandre (Marc-Andre Lafortune). Category set to core Assignee set to marcandre (Marc-Andre Lafortune) Target version set to current: 2.1.0 > Instinctively I'd say that the documentation has it right and it ought to take any callable. Agreed, I'll address this. Thanks ---------------------------------------- Bug #8641: Enumerator size argument is either mis-documented or should accept any callable https://bugs.ruby-lang.org/issues/8641#change-40551 Author: avdi (Avdi Grimm) Status: Open Priority: Normal Assignee: marcandre (Marc-Andre Lafortune) Category: core Target version: current: 2.1.0 ruby -v: ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-linux] Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN I ran into this while wrapping Enumerators around Queues. The Enumerator docs state: * The optional parameter can be used to specify how to calculate the size * in a lazy fashion (see Enumerator#size). It can either be a value or * a callable object. However: require 'thread' q = Queue.new eq = Enumerator.new(q.method(:size)) do |y| loop do y << q.pop end end eq.size # => # ~> -:3:in `initialize': no implicit conversion of Method into Integer (TypeError) # ~> from -:3:in `new' # ~> from -:3:in `
' It looks like the size can't be any callable; it must be Proc a or an Integer. The code uses rb_obj_is_proc(). Instinctively I'd say that the documentation has it right and it ought to take any callable. But if there's some reason it's limited to Procs, the docs should be changed. If anyone can point me in the right direction I'm happy to do the legwork on this. -- http://bugs.ruby-lang.org/