Replace

class
Superclass
Pushdown::Transition

A replace transition – remove all currents states from the stack and add a different one.

Attributes

data[R]

The data object to pass to the state_class's constructor

state_class[R]

The State to replace the stack members with.

Public Class Methods

anchor
new( name, state_class, data=nil )

Create a transition that will Replace all the states on the current stack with an instance of the given state_class.

# File lib/pushdown/transition/replace.rb, line 12
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/replace.rb, line 34
def apply( stack )
        state = self.state_class.new( self.data )

        self.log.debug "replacing current state with a new state: %p" % [ state ]
        while ( old_state = stack.pop )
                old_state.on_stop
        end

        stack.push( state )
        state.on_start

        return stack
end