Class: VariableScopeStack
- Inherits:
-
Object
- Object
- VariableScopeStack
- Defined in:
- lib/zombie_killer/variable_scope.rb
Overview
A stack of VariableScope
Instance Method Summary collapse
-
#initialize ⇒ VariableScopeStack
constructor
A new instance of VariableScopeStack.
-
#innermost ⇒ Object
The innermost, or current VariableScope.
-
#with_copy(&block) ⇒ Object
Run block using a copy of the innermost scope.
-
#with_new(&block) ⇒ Object
Run block using a new clean scope.
Constructor Details
#initialize ⇒ VariableScopeStack
Returns a new instance of VariableScopeStack.
37 38 39 40 |
# File 'lib/zombie_killer/variable_scope.rb', line 37 def initialize outer_scope = VariableScope.new @stack = [outer_scope] end |
Instance Method Details
#innermost ⇒ Object
The innermost, or current VariableScope
43 44 45 |
# File 'lib/zombie_killer/variable_scope.rb', line 43 def innermost @stack.last end |
#with_copy(&block) ⇒ Object
Run block using a copy of the innermost scope
57 58 59 60 61 |
# File 'lib/zombie_killer/variable_scope.rb', line 57 def with_copy(&block) @stack.push innermost.dup block.call @stack.pop end |
#with_new(&block) ⇒ Object
Run block using a new clean scope
49 50 51 52 53 |
# File 'lib/zombie_killer/variable_scope.rb', line 49 def with_new(&block) @stack.push VariableScope.new block.call @stack.pop end |