Class: Puppet::Pops::Types::StepIterator Private

Inherits:
Iterator show all
Includes:
Enumerable
Defined in:
lib/puppet/pops/types/iterable.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Methods inherited from Iterator

#all?, #any?, #element_type, #map, #method_missing, #reduce, #respond_to_missing?, #step, #step_iterator, #to_s, #unbounded?

Methods included from Iterable

asserted_iterable, #each, #element_type, #hash_style?, on, #step, #to_a, unbounded?, #unbounded?

Constructor Details

#initialize(element_type, enumeration, step_size) ⇒ StepIterator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of StepIterator.

Raises:

  • (ArgumentError)


283
284
285
286
287
# File 'lib/puppet/pops/types/iterable.rb', line 283

def initialize(element_type, enumeration, step_size)
  super(element_type, enumeration)
  raise ArgumentError if step_size <= 0
  @step_size = step_size
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Puppet::Pops::Types::Iterator

Instance Method Details

#nextObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



289
290
291
292
293
294
295
296
297
298
299
# File 'lib/puppet/pops/types/iterable.rb', line 289

def next
  result = @enumeration.next
  skip = @step_size - 1
  if skip > 0
    begin
      skip.times { @enumeration.next }
    rescue StopIteration
    end
  end
  result
end

#reverse_each(&block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



301
302
303
304
# File 'lib/puppet/pops/types/iterable.rb', line 301

def reverse_each(&block)
  r = Iterator.new(@element_type, to_a.reverse_each)
  block_given? ? r.each(&block) : r
end

#sizeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



306
307
308
# File 'lib/puppet/pops/types/iterable.rb', line 306

def size
  super / @step_size
end