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.3.0"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.each!(arr) ⇒ Object



11
12
13
# File 'lib/hyper_iterator.rb', line 11

def self.each!(arr)
  arr.each! { |el| yield el }
end

Instance Method Details

#each!Object



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

def each!
  while count > 0
    yield shift
  end
  nil
end

#each_slice!(slice_size) ⇒ 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)
  i = 0

  while count > 0
    current_slice = []
    while i < slice_size && count > 0
      current_slice << shift
      i += 1
    end
    yield current_slice
    i = 0
  end
  nil
end