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.
39 40 41 42 |
# File 'lib/zombie_killer/variable_scope.rb', line 39 def initialize outer_scope = VariableScope.new @stack = [outer_scope] end |
Instance Method Details
#innermost ⇒ Object
The innermost, or current VariableScope
45 46 47 |
# File 'lib/zombie_killer/variable_scope.rb', line 45 def innermost @stack.last end |
#with_copy(&block) ⇒ Object
Run block using a copy of the innermost scope
59 60 61 62 63 |
# File 'lib/zombie_killer/variable_scope.rb', line 59 def with_copy(&block) @stack.push innermost.dup block.call @stack.pop end |
#with_new(&block) ⇒ Object
Run block using a new clean scope
51 52 53 54 55 |
# File 'lib/zombie_killer/variable_scope.rb', line 51 def with_new(&block) @stack.push VariableScope.new block.call @stack.pop end |