Class: Cond::CondPrivate::CodeSection
Overview
Instance Method Summary
collapse
gensym, recycle, track
Constructor Details
#initialize(with, &block) ⇒ CodeSection
Returns a new instance of CodeSection.
256
257
258
259
260
261
262
|
# File 'lib/cond.rb', line 256
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
264
265
266
267
268
269
270
271
272
273
274
275
276
|
# File 'lib/cond.rb', line 264
def again(*args)
@again_args = (
case args.size
when 0
[]
when 1
args.first
else
args
end
)
throw @again
end
|
#leave(*args) ⇒ Object
278
279
280
281
282
283
284
285
286
287
|
# File 'lib/cond.rb', line 278
def leave(*args)
case args.size
when 0
throw @leave
when 1
throw @leave, args.first
else
throw @leave, args
end
end
|
#run ⇒ Object
289
290
291
292
293
294
295
296
297
298
299
|
# File 'lib/cond.rb', line 289
def run
catch(@leave) {
while true
catch(@again) {
Cond.send(@with, Hash.new) {
throw @leave, @block.call(*@again_args)
}
}
end
}
end
|