Module: HyperIterator

Defined in:
lib/hyper_iterator.rb,
lib/iterators/each_bang.rb,
lib/hyper_iterator/version.rb,
lib/iterators/each_slice_bang.rb

Constant Summary collapse

AVAILABLE_METHODS =
[
  :each_slice!,
  :each!
].freeze
VERSION =
"0.2.2"

Instance Method Summary collapse

Instance Method Details

#each!(&blk) ⇒ Object



2
3
4
5
6
7
# File 'lib/iterators/each_bang.rb', line 2

def each!(&blk)
  while count > 0
    blk.call(shift)
  end
  nil
end

#each_slice!(slice_size, &blk) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/iterators/each_slice_bang.rb', line 2

def each_slice!(slice_size, &blk)
  i = 0

  while count > 0
    current_slice = []
    while i < slice_size && count > 0
      current_slice << shift
      i += 1
    end
    blk.call(current_slice)
    i = 0
  end
  nil
end