Class: Ribbon::Plugins::BlockStack

Inherits:
Object
  • Object
show all
Defined in:
lib/ribbon/plugins/block_stack.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope = nil) ⇒ BlockStack

Returns a new instance of BlockStack


5
6
7
8
# File 'lib/ribbon/plugins/block_stack.rb', line 5

def initialize(scope=nil)
  @scope = scope
  @_stack = []
end

Instance Attribute Details

#scopeObject

Returns the value of attribute scope


3
4
5
# File 'lib/ribbon/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/ribbon/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

#dupObject


10
11
12
13
14
# File 'lib/ribbon/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/ribbon/plugins/block_stack.rb', line 16

def push(&block)
  @_stack.push(block)
end