Class: ExpressTemplates::Expander::Stack
- Inherits:
-
Object
- Object
- ExpressTemplates::Expander::Stack
- Defined in:
- lib/express_templates/expander.rb
Instance Method Summary collapse
- #<<(child) ⇒ Object
- #all ⇒ Object
- #ascend! ⇒ Object
- #current ⇒ Object
- #descend! ⇒ Object
- #dump ⇒ Object
-
#initialize ⇒ Stack
constructor
A new instance of Stack.
- #next ⇒ Object
Constructor Details
#initialize ⇒ Stack
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 |
#all ⇒ Object
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 |
#current ⇒ Object
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 |
#dump ⇒ Object
109 110 111 112 113 |
# File 'lib/express_templates/expander.rb', line 109 def dump puts "Current frame: #{@frame}" require 'pp' pp all end |
#next ⇒ Object
124 125 126 |
# File 'lib/express_templates/expander.rb', line 124 def next @stack[@frame+1] ||= [] end |