Class: EnumUtils::ExhaustibleIter

Inherits:
Object
  • Object
show all
Defined in:
lib/enum_utils/exhaustible_iter.rb

Overview

This is an enumerator wrapper that always caches 1 item in its buffer, and provides the ability to check if underlying enumerator is exhausted.

Constant Summary collapse

EXHAUSTED =
Object.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ ExhaustibleIter

Returns a new instance of ExhaustibleIter.



9
# File 'lib/enum_utils/exhaustible_iter.rb', line 9

def initialize(source); @source = source; pull        end

Instance Attribute Details

#buff_valueObject (readonly)

Returns the value of attribute buff_value.



7
8
9
# File 'lib/enum_utils/exhaustible_iter.rb', line 7

def buff_value
  @buff_value
end

Instance Method Details

#exhausted?Boolean

Returns:

  • (Boolean)


10
# File 'lib/enum_utils/exhaustible_iter.rb', line 10

def exhausted?;         @buff_value.equal?(EXHAUSTED) end

#nextObject



11
# File 'lib/enum_utils/exhaustible_iter.rb', line 11

def next;               @buff_value.tap { pull }      end