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.



97
98
99
100
# File 'lib/express_templates/expander.rb', line 97

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

Instance Method Details

#<<(child) ⇒ Object



112
113
114
115
# File 'lib/express_templates/expander.rb', line 112

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

#allObject



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

def all
  @stack
end

#ascend!Object



132
133
134
135
136
137
# File 'lib/express_templates/expander.rb', line 132

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

#currentObject



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

def current
  @stack[@frame]
end

#descend!Object



125
126
127
128
129
130
# File 'lib/express_templates/expander.rb', line 125

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

#dumpObject



106
107
108
109
110
# File 'lib/express_templates/expander.rb', line 106

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

#nextObject



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

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