[ruby-trunk - Bug #6152][Open] Enumerator::Lazy#take

Issue #6152 has been reported by Nobuhiro IMAI.


Bug #6152: Enumerator::Lazy#take
https://bugs.ruby-lang.org/issues/6152

Author: Nobuhiro IMAI
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 2.0.0dev (2012-03-16 trunk 35049) [x86_64-linux]

=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

Issue #6152 has been updated by Shugo M…

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の方のバグだったので修正しました。


Bug #6152: Enumerator::Lazy#take
https://bugs.ruby-lang.org/issues/6152#change-24621

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

=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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs