Class: Cond::CodeSection
Overview
Instance Method Summary
collapse
gensym, recycle, track
Constructor Details
#initialize(with, &block) ⇒ CodeSection
Returns a new instance of CodeSection.
6
7
8
9
10
11
12
|
# File 'lib/cond/code_section.rb', line 6
def initialize(with, &block)
@with = with
@block = block
@again_args = []
@leave, @again = gensym, gensym
SymbolGenerator.track(self, @leave, @again)
end
|
Instance Method Details
#again(*args) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/cond/code_section.rb', line 14
def again(*args)
@again_args = (
case args.size
when 0
[]
when 1
args.first
else
args
end
)
throw @again
end
|
#leave(*args) ⇒ Object
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/cond/code_section.rb', line 28
def leave(*args)
case args.size
when 0
throw @leave
when 1
throw @leave, args.first
else
throw @leave, args
end
end
|
#run ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/cond/code_section.rb', line 39
def run
catch(@leave) {
while true
catch(@again) {
Cond.send(@with, Hash.new) {
throw @leave, @block.call(*@again_args)
}
}
end
}
end
|