Sha256: a08aea89b75d26bdb7a5ad3b48e086e834df99806049c4ea9bf01bf6b32eb8cc
Contents?: true
Size: 722 Bytes
Versions: 38
Compression:
Stored size: 722 Bytes
Contents
unless Enumerable.method_defined? :slice_when require 'backports/tools/arguments' require 'backports/1.9.1/enumerator/new' module Enumerable def slice_when(&block) raise ArgumentError, 'tried to create Proc object without a block' unless block enum = self Enumerator.new do |y| acc = [] prev = Backports::Undefined enum.each do |*elem| elem = elem.first if elem.length == 1 unless prev == Backports::Undefined if block.call(prev, elem) y.yield acc acc = [] end end acc << elem prev = elem end y.yield acc unless acc.empty? end end end end
Version data entries
38 entries across 38 versions & 3 rubygems