Ruby 2.5.0 リファレンスマニュアル > ライブラリ一覧 > 組み込みライブラリ > Enumerator::Lazyクラス > slice_before

instance method Enumerator::Lazy#slice_before

slice_before(pattern) -> Enumerator::Lazy[permalink][rdoc]
slice_before {|elt| bool } -> Enumerator::Lazy
slice_before(initial_state) {|elt, state| bool } -> Enumerator::Lazy

Enumerable#slice_before と同じですが、配列ではなく Enumerator::Lazy を返します。



1.step.lazy.slice_before { |e| e.even? }
# => #<Enumerator::Lazy: #<Enumerator: #<Enumerator::Generator:0x00007f9f31844ce8>:each>>

1.step.lazy.slice_before { |e| e % 3 == 0 }.take(5).force
# => [[1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11], [12, 13, 14]]

[SEE_ALSO] Enumerable#slice_before