class Ribbon::Plugins::AroundStack

Attributes

scope[RW]
subject[R]

Public Class Methods

new(subject, scope=nil) click to toggle source
# File lib/ribbon/plugins/around_stack.rb, line 6
def initialize(subject, scope=nil)
  @subject = subject.to_sym
  @scope = scope
  @_stack = []
end

Public Instance Methods

call(*args, &block) click to toggle source
# File lib/ribbon/plugins/around_stack.rb, line 28
def call(*args, &block)
  raise Errors::Error, "Must pass block" unless block_given?
  call_stack = @_stack.dup

  inner_most = WrappedBlock.new(&block)
  call_stack.unshift(inner_most)

  outer_most = call_stack.pop
  outer_most.call(call_stack, *args)

  # This shouldn't happen unless the AroundStack isn't functioning properly.
  raise Errors::Error, "Block passed was not called!" unless inner_most.called?

  inner_most.retval
end
dup() click to toggle source
# File lib/ribbon/plugins/around_stack.rb, line 20
def dup
  AroundStack.new(subject, scope).tap { |stack|
    @_stack.each { |wrapper|
      stack.push(&wrapper.block)
    }
  }
end
push(&block) click to toggle source
# File lib/ribbon/plugins/around_stack.rb, line 12
def push(&block)
  raise Errors::Error, "Must pass block" unless block_given?

  AroundWrapper.new(self, subject, &block).tap { |wrapper|
    @_stack.push(wrapper)
  }
end