Class: Pushdown::Transition::Pop

Inherits:
Pushdown::Transition show all
Defined in:
lib/pushdown/transition/pop.rb

Overview

A push transition – add an instance of a given State to the top of the state stack.

Instance Attribute Summary collapse

Attributes inherited from Pushdown::Transition

#name

Instance Method Summary collapse

Methods inherited from Pushdown::Transition

inherited, #initialize, #type_name

Constructor Details

This class inherits a constructor from Pushdown::Transition

Instance Attribute Details

#popped_stateObject (readonly)

Return the state that was popped



19
20
21
# File 'lib/pushdown/transition/pop.rb', line 19

def popped_state
  @popped_state
end

Instance Method Details

#apply(stack) ⇒ Object

Apply the transition to the given stack.

Raises:

  • (Pushdown::TransitionError)


23
24
25
26
27
28
29
30
31
32
33
# File 'lib/pushdown/transition/pop.rb', line 23

def apply( stack )
  raise Pushdown::TransitionError, "can't pop from an empty stack" if stack.empty?
  raise Pushdown::TransitionError, "can't pop the only state on the stack" if stack.length == 1

  self.log.debug "popping a state"
  @popped_state = stack.pop
  @popped_state.on_stop
  stack.last.on_resume

  return stack
end