Skip to content

Commit

Permalink
Showing 2 changed files with 25 additions and 5 deletions.
5 changes: 0 additions & 5 deletions spec/truffle/tags/core/enumerable/slice_when_tags.txt

This file was deleted.

25 changes: 25 additions & 0 deletions truffle/src/main/ruby/core/enumerable.rb
Original file line number Diff line number Diff line change
@@ -217,6 +217,31 @@ def slice_before(arg = undefined, &block)
end
end

def slice_when(&block)
block = Proc.new(block)
Enumerator.new do |yielder|
accumulator = nil
prev = nil
each do |*elem|
elem = elem[0] if elem.size == 1
if accumulator == nil

This comment has been minimized.

Copy link
@nirvdrum

nirvdrum Aug 25, 2016

Contributor

The rest of this file seems to use nil?. I'd just update to match.

accumulator = [elem]
prev = elem
else
start_new = block.yield(prev, elem)
if start_new
yielder.yield accumulator if accumulator
accumulator = [elem]
else
accumulator << elem
end
prev = elem
end
end
yielder.yield accumulator if accumulator
end
end

def to_a(*arg)
ary = []
each(*arg) do

0 comments on commit 6fc8ec6

Please sign in to comment.