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: c5dcaf08e8e5
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 70ed311fd1cf
Choose a head ref
  • 5 commits
  • 3 files changed
  • 1 contributor

Commits on Jan 22, 2016

  1. Copy the full SHA
    05d88aa View commit details

Commits on Jan 28, 2016

  1. Reword spec description

    jsyeo committed Jan 28, 2016
    Copy the full SHA
    ae134d8 View commit details
  2. Copy the full SHA
    05f6818 View commit details
  3. Copy the full SHA
    c136f19 View commit details
  4. Merge pull request #3584 from jsyeo/jsyeo-slice-failing-specs

    Fix issue in slice_(after|before) when iterator method yields more than one value
    jsyeo committed Jan 28, 2016
    Copy the full SHA
    70ed311 View commit details
Showing with 20 additions and 2 deletions.
  1. +4 −2 kernel/common/enumerable.rb
  2. +8 −0 spec/ruby/core/enumerable/slice_after_spec.rb
  3. +8 −0 spec/ruby/core/enumerable/slice_before_spec.rb
6 changes: 4 additions & 2 deletions kernel/common/enumerable.rb
Original file line number Diff line number Diff line change
@@ -140,7 +140,8 @@ def slice_before(pattern = undefined, &block)

Enumerator.new do |yielder|
accumulator = nil
each do |element|
each do
element = Rubinius.single_block_arg
start_new = block.yield(element)
if start_new
yielder.yield accumulator if accumulator
@@ -164,7 +165,8 @@ def slice_after(pattern = undefined, &block)

Enumerator.new do |yielder|
accumulator = nil
each do |element|
each do
element = Rubinius.single_block_arg
end_chunk = block.yield(element)
accumulator ||= []
if end_chunk
8 changes: 8 additions & 0 deletions spec/ruby/core/enumerable/slice_after_spec.rb
Original file line number Diff line number Diff line change
@@ -46,6 +46,14 @@
end
end

describe "when an iterator method yields more than one value" do
it "processes all yielded values" do
enum = EnumerableSpecs::YieldsMulti.new
result = enum.slice_after { |i| i == [3, 4, 5] }.to_a
result.should == [[[1, 2], [3, 4, 5]], [[6, 7, 8, 9]]]
end
end

it "raises an ArgumentError when given an incorrect number of arguments" do
lambda { @enum.slice_after("one", "two") }.should raise_error(ArgumentError)
lambda { @enum.slice_after }.should raise_error(ArgumentError)
8 changes: 8 additions & 0 deletions spec/ruby/core/enumerable/slice_before_spec.rb
Original file line number Diff line number Diff line change
@@ -52,6 +52,14 @@
lambda { @enum.slice_before }.should raise_error(ArgumentError)
end

describe "when an iterator method yields more than one value" do
it "processes all yielded values" do
enum = EnumerableSpecs::YieldsMulti.new
result = enum.slice_before { |i| i == [3, 4, 5] }.to_a
result.should == [[[1, 2]], [[3, 4, 5], [6, 7, 8, 9]]]
end
end

before :all do
@method_args = [3]
end