Class: Subaltern::LoopFunction

Inherits:
Function
  • Object
show all
Defined in:
lib/subaltern/kernel.rb

Instance Method Summary collapse

Constructor Details

#initializeLoopFunction

Returns a new instance of LoopFunction.



35
36
# File 'lib/subaltern/kernel.rb', line 35

def initialize
end

Instance Method Details

#call(context, tree) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/subaltern/kernel.rb', line 38

def call(context, tree)

  return nil unless context['__block']
    # a real Ruby would return an Enumerator instance

  con = Context.new(context, {})

  loop do

    begin

      r = context['__block'].call(con, [], false)
        # new_context is false

    rescue Command => c

      case c.name
        when 'break' then break c
        when 'next' then next c
        else raise c
      end
    end
  end
end