Class: ExpressTemplates::Expander::Stack

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

Instance Method Summary collapse

Constructor Details

#initializeStack

Returns a new instance of Stack.



100
101
102
103
# File 'lib/express_templates/expander.rb', line 100

def initialize
  @stack = [[]]
  @frame = 0
end

Instance Method Details

#<<(child) ⇒ Object



115
116
117
118
# File 'lib/express_templates/expander.rb', line 115

def <<(child)
  current << child
  child
end

#allObject



105
106
107
# File 'lib/express_templates/expander.rb', line 105

def all
  @stack
end

#ascend!Object



135
136
137
138
139
140
# File 'lib/express_templates/expander.rb', line 135

def ascend!
  raise "Cannot ascend" if @frame <= 0
  current.clear ;
  self.next.clear
  @frame -= 1
end

#currentObject



120
121
122
# File 'lib/express_templates/expander.rb', line 120

def current
  @stack[@frame]
end

#descend!Object



128
129
130
131
132
133
# File 'lib/express_templates/expander.rb', line 128

def descend!
  @frame += 1
  @stack[@frame] ||= []
  @stack[@frame].clear
  @frame
end

#dumpObject



109
110
111
112
113
# File 'lib/express_templates/expander.rb', line 109

def dump
  puts "Current frame: #{@frame}"
  require 'pp'
  pp all
end

#nextObject



124
125
126
# File 'lib/express_templates/expander.rb', line 124

def next
  @stack[@frame+1] ||= []
end