Class: Reconsidered::Labels
- Inherits:
-
Object
- Object
- Reconsidered::Labels
- Defined in:
- lib/reconsidered.rb
Instance Method Summary collapse
-
#goto(sym) ⇒ Object
Return to the location in the code labeled with sym.
-
#initialize ⇒ Labels
constructor
Allocate a new private Label set.
-
#label(sym) ⇒ Object
Create a new label which, when used with #goto, will return to the current location in the program.
Constructor Details
#initialize ⇒ Labels
Allocate a new private Label set. Usually not needed – use Kernel#__label__ and Kernel#__goto__ isnstead.
See “Private Labels” in the README for details
21 22 23 |
# File 'lib/reconsidered.rb', line 21 def initialize @labels = {} end |
Instance Method Details
#goto(sym) ⇒ Object
Return to the location in the code labeled with sym
34 35 36 37 |
# File 'lib/reconsidered.rb', line 34 def goto sym raise NoSuchLabel unless @labels[sym].instance_of? Continuation @labels[sym].call end |
#label(sym) ⇒ Object
Create a new label which, when used with #goto, will return to the current location in the program
27 28 29 30 31 |
# File 'lib/reconsidered.rb', line 27 def label sym callcc do |cc| @labels[sym] = cc end end |