Class: Enumerator::Memoizing
- Inherits:
-
Enumerator
- Object
- Enumerator
- Enumerator::Memoizing
- Defined in:
- lib/enumerator/memoizing.rb
Instance Method Summary collapse
-
#initialize(obj, *args) ⇒ Memoizing
constructor
A new instance of Memoizing.
Methods inherited from Enumerator
Constructor Details
#initialize(obj, *args) ⇒ Memoizing
Returns a new instance of Memoizing.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/enumerator/memoizing.rb', line 8 def initialize(obj, *args) if obj.kind_of? Enumerator base_enumerator = obj else base_enumerator = Enumerator.new(obj, *args) end memoized_sequence = [] super() do |yielder| memoized_sequence.each do |m| yielder << m end loop do x = base_enumerator.next memoized_sequence << x yielder << x end end end |