Class: Pushdown::Transition::Pop
- Inherits:
-
Pushdown::Transition
- Object
- Pushdown::Transition
- Pushdown::Transition::Pop
- 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
-
#popped_state ⇒ Object
readonly
Return the state that was popped.
Attributes inherited from Pushdown::Transition
Instance Method Summary collapse
-
#apply(stack) ⇒ Object
Apply the transition to the given
stack.
Methods inherited from Pushdown::Transition
inherited, #initialize, #type_name
Constructor Details
This class inherits a constructor from Pushdown::Transition
Instance Attribute Details
#popped_state ⇒ Object (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.
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 |