Class: Reconsidered::Labels

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

Instance Method Summary collapse

Constructor Details

#initializeLabels

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

Raises:



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