Class: InfiniteStream

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

Overview

direct copy, with adaptations, of Generator class by Jim Weirich in Hal Fulton's book "The Ruby Way."

Direct Known Subclasses

Feigenbaum, InfiniteBeats

Instance Method Summary collapse

Constructor Details

#initializeInfiniteStream

Returns a new instance of InfiniteStream



5
6
7
8
9
10
11
# File 'lib/infinite_stream.rb', line 5

def initialize
  callcc do |context|
    @generator_context = context
    return
  end
  generating_loop
end

Instance Method Details

#generate(value) ⇒ Object



18
19
20
21
22
23
# File 'lib/infinite_stream.rb', line 18

def generate(value)
  callcc do |context|
    @generator_context = context
    @main_context[value]
  end
end

#nextObject



12
13
14
15
16
17
# File 'lib/infinite_stream.rb', line 12

def next
  callcc do |here|
    @main_context = here
    @generator_context[]
  end
end