Push

class
Superclass
Pushdown::Transition

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

Attributes

data[R]

The data object to pass to the state_class's constructor

state_class[R]

The State to push to.

Public Class Methods

anchor
new( name, state_class, data=nil )

Create a transition that will Push an instance of the given state_class to the stack.

# File lib/pushdown/transition/push.rb, line 13
def initialize( name, state_class, data=nil )
        super( name )

        @state_class = state_class
        @data = data
end

Public Instance Methods

anchor
apply( stack )

Apply the transition to the given stack.

# File lib/pushdown/transition/push.rb, line 35
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