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.
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 |
#all ⇒ Object
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 |
#current ⇒ Object
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 |
#dump ⇒ Object
106 107 108 109 110 |
# File 'lib/express_templates/expander.rb', line 106 def dump puts "Current frame: #{@frame}" require 'pp' pp all end |
#next ⇒ Object
121 122 123 |
# File 'lib/express_templates/expander.rb', line 121 def next @stack[@frame+1] ||= [] end |