A replace transition – remove all currents states from the stack and add a different one.
The data object to pass to the state_class
's constructor
The State to replace the stack members with.
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
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