Project

General

Profile

Bug #6152

Enumerator::Lazy#take

Added by no6v (Nobuhiro IMAI) over 7 years ago. Updated over 7 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 2.0.0dev (2012-03-16 trunk 35049) [x86_64-linux]
Backport:
[ruby-dev:45370]

Description

=begin
以下はテストにある Step クラスですが、

class Step
include Enumerable
attr_reader :current, :args

def initialize(enum)
@enum = enum
@current = nil
@args = nil
end

def each(*args)
@args = args
@enum.each{|i| @current = i; yield i}
end
end

a = Step.new(1..10)
a.take(5).first # => 1
a.current # => 5
a.lazy.take(5).first # => 1
a.current # => 1
a.take(5).first(5) # => [1, 2, 3, 4, 5]
a.current # => 5
a.lazy.take(5).first(5) # => [1, 2, 3, 4, 5]
a.current # => 5
a.take(5).to_a # => [1, 2, 3, 4, 5]
a.current # => 5
a.lazy.take(5).to_a # => [1, 2, 3, 4, 5]
a.current # => 6

最後の例で current が 6 まで進むのは正しいでしょうか?
=end

Associated revisions

Revision 29f73009
Added by shugo (Shugo Maeda) over 7 years ago

  • enumerator.c (lazy_take): don't enumerate an extra value. [ruby-dev:45370] [Bug #6152]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35050 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 35050
Added by shugo (Shugo Maeda) over 7 years ago

  • enumerator.c (lazy_take): don't enumerate an extra value. [ruby-dev:45370] [Bug #6152]

Revision 35050
Added by shugo (Shugo Maeda) over 7 years ago

  • enumerator.c (lazy_take): don't enumerate an extra value. [ruby-dev:45370] [Bug #6152]

Revision 35050
Added by shugo (Shugo Maeda) over 7 years ago

  • enumerator.c (lazy_take): don't enumerate an extra value. [ruby-dev:45370] [Bug #6152]

Revision 35050
Added by shugo (Shugo Maeda) over 7 years ago

  • enumerator.c (lazy_take): don't enumerate an extra value. [ruby-dev:45370] [Bug #6152]

Revision 35050
Added by shugo (Shugo Maeda) over 7 years ago

  • enumerator.c (lazy_take): don't enumerate an extra value. [ruby-dev:45370] [Bug #6152]

Revision 35050
Added by shugo (Shugo Maeda) over 7 years ago

  • enumerator.c (lazy_take): don't enumerate an extra value. [ruby-dev:45370] [Bug #6152]

History

Updated by shugo (Shugo Maeda) over 7 years ago

  • Status changed from Open to Closed

Nobuhiro IMAI wrote:

以下はテストにある Step クラスですが、
(snip)
a.lazy.take(5).to_a # => [1, 2, 3, 4, 5]
a.current # => 6

最後の例で current が 6 まで進むのは正しいでしょうか?

正しくないですね。takeの方のバグだったので修正しました。

Also available in: Atom PDF