Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: dd1b24ad848d
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d791723f57e3
Choose a head ref
  • 4 commits
  • 3 files changed
  • 2 contributors

Commits on Jun 5, 2015

  1. Copy the full SHA
    e18155b View commit details
  2. Copy the full SHA
    df298da View commit details
  3. Copy the full SHA
    639adee View commit details

Commits on Jun 11, 2015

  1. Merge pull request #3426 from kachick/fix-lazy-take-iteration

    Fix stop points of Enumerator::Lazy#take
    brixen committed Jun 11, 2015
    Copy the full SHA
    d791723 View commit details
Showing with 13 additions and 2 deletions.
  1. +3 −0 kernel/common/enumerator.rb
  2. +10 −0 spec/ruby/core/enumerator/lazy/take_spec.rb
  3. +0 −2 spec/tags/ruby/core/enumerator/lazy/take_tags.txt
3 changes: 3 additions & 0 deletions kernel/common/enumerator.rb
Original file line number Diff line number Diff line change
@@ -264,11 +264,14 @@ def take(n)
current_size
end

return to_enum(:cycle, 0).lazy if n.zero?

taken = 0
Lazy.new(self, set_size) do |yielder, *args|
if taken < n
yielder.yield(*args)
taken += 1
raise StopLazyError unless taken < n
else
raise StopLazyError
end
10 changes: 10 additions & 0 deletions spec/ruby/core/enumerator/lazy/take_spec.rb
Original file line number Diff line number Diff line change
@@ -36,6 +36,11 @@
@eventsmixed.take(1).force
ScratchPad.recorded.should == [:before_yield]
end

it "stops without iterations if the given argument is 0" do
@eventsmixed.take(0).force
ScratchPad.recorded.should == []
end
end

describe "on a nested Lazy" do
@@ -51,6 +56,11 @@
@eventsmixed.take(10).take(1).force
ScratchPad.recorded.should == [:before_yield]
end

it "stops without iterations if the given argument is 0" do
@eventsmixed.take(10).take(0).force
ScratchPad.recorded.should == []
end
end
end
end
2 changes: 0 additions & 2 deletions spec/tags/ruby/core/enumerator/lazy/take_tags.txt

This file was deleted.