Class: Plugins::BlockStack
- Inherits:
-
Object
- Object
- Plugins::BlockStack
- Defined in:
- lib/plugins/block_stack.rb
Instance Attribute Summary collapse
-
#scope ⇒ Object
Returns the value of attribute scope.
Instance Method Summary collapse
- #call(*args) ⇒ Object
- #dup ⇒ Object
-
#initialize(scope = nil) ⇒ BlockStack
constructor
A new instance of BlockStack.
- #push(&block) ⇒ Object
Constructor Details
#initialize(scope = nil) ⇒ BlockStack
Returns a new instance of BlockStack.
5 6 7 8 |
# File 'lib/plugins/block_stack.rb', line 5 def initialize(scope=nil) @scope = scope @_stack = [] end |
Instance Attribute Details
#scope ⇒ Object
Returns the value of attribute scope.
3 4 5 |
# File 'lib/plugins/block_stack.rb', line 3 def scope @scope end |
Instance Method Details
#call(*args) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/plugins/block_stack.rb', line 20 def call(*args) @_stack.reverse_each { |block| if scope scope.instance_exec(*args, &block) else block.call(*args) end } end |
#dup ⇒ Object
10 11 12 13 14 |
# File 'lib/plugins/block_stack.rb', line 10 def dup BlockStack.new.tap { |stack| @_stack.each { |block| stack.push(&block) } } end |
#push(&block) ⇒ Object
16 17 18 |
# File 'lib/plugins/block_stack.rb', line 16 def push(&block) @_stack.push(block) end |