Class: Pushdown::Transition::Push
- Inherits:
-
Pushdown::Transition
- Object
- Pushdown::Transition
- Pushdown::Transition::Push
- Defined in:
- lib/pushdown/transition/push.rb
Overview
A push transition – add an instance of a given State to the top of the state stack.
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
The data object to pass to the #state_class’s constructor.
-
#state_class ⇒ Object
readonly
The State to push to.
Attributes inherited from Pushdown::Transition
Instance Method Summary collapse
-
#apply(stack) ⇒ Object
Apply the transition to the given
stack. -
#initialize(name, state_class, data = nil) ⇒ Push
constructor
Create a transition that will Push an instance of the given
state_classto the stack.
Methods inherited from Pushdown::Transition
Constructor Details
#initialize(name, state_class, data = nil) ⇒ Push
Create a transition that will Push an instance of the given state_class to the stack.
14 15 16 17 18 19 |
# File 'lib/pushdown/transition/push.rb', line 14 def initialize( name, state_class, data=nil ) super( name ) @state_class = state_class @data = data end |
Instance Attribute Details
#data ⇒ Object (readonly)
The data object to pass to the #state_class’s constructor
32 33 34 |
# File 'lib/pushdown/transition/push.rb', line 32 def data @data end |
#state_class ⇒ Object (readonly)
The State to push to.
28 29 30 |
# File 'lib/pushdown/transition/push.rb', line 28 def state_class @state_class end |
Instance Method Details
#apply(stack) ⇒ Object
Apply the transition to the given stack.
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/pushdown/transition/push.rb', line 36 def apply( stack ) state = self.state_class.new( self.data ) self.log.debug "pushing a new state: %p" % [ state ] stack.last.on_pause if stack.last stack.push( state ) state.on_start return stack end |