Module: HyperIterator
- Defined in:
- lib/hyper_iterator.rb,
lib/iterators/each_bang.rb,
lib/hyper_iterator/version.rb,
lib/iterators/each_slice_bang.rb
Defined Under Namespace
Modules: EachBang
Constant Summary collapse
- AVAILABLE_METHODS =
[ :each_slice!, :each! ].freeze
- VERSION =
"0.3.1"
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.each!(iterable) ⇒ Object
11 12 13 |
# File 'lib/hyper_iterator.rb', line 11 def self.each!(iterable) iterable.each! { |el| yield el } end |
Instance Method Details
#each_slice!(slice_size) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/iterators/each_slice_bang.rb', line 2 def each_slice!(slice_size) if slice_size.nil? || !slice_size.is_a?(Integer) || slice_size <= 0 raise ArgumentError, "invalid slice size" end 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 |