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 included from Enumerable

#uniq

Methods inherited from Iterator

#element_type, #method_missing, #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)

256
257
258
259
260
# File 'lib/puppet/pops/types/iterable.rb', line 256

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.


262
263
264
265
266
267
268
269
270
271
272
# File 'lib/puppet/pops/types/iterable.rb', line 262

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.


274
275
276
277
# File 'lib/puppet/pops/types/iterable.rb', line 274

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.


279
280
281
# File 'lib/puppet/pops/types/iterable.rb', line 279

def size
  super / @step_size
end