Module: GoTo

Defined in:
lib/rubyhacks.rb

Defined Under Namespace

Classes: Goto, Label

Constant Summary collapse

STACK =
[]

Instance Method Summary collapse

Instance Method Details

#frame_end_goto ⇒ Object



956
957
958
959
960
961
962
963
964
965
966
967
968
# File 'lib/rubyhacks.rb', line 956

def frame_end_goto
  frame = STACK.pop
  idx = 0

  begin
    for i in (idx...frame.size)
      frame[i].block.call if frame[i].block
    end
  rescue Goto => g
    idx = frame.index(g.label)
    retry
  end
end

#frame_start_goto ⇒ Object



952
953
954
# File 'lib/rubyhacks.rb', line 952

def frame_start_goto
  STACK << []
end

#goto(label) ⇒ Object

Raises:



970
971
972
# File 'lib/rubyhacks.rb', line 970

def goto(label)
  raise Goto.new(label)
end

#label_goto(sym, &block) ⇒ Object



948
949
950
# File 'lib/rubyhacks.rb', line 948

def label_goto(sym, &block)
  STACK.last << Label.new(sym, block)
end