Class: Pushdown::Transition
- Inherits:
-
Object
- Object
- Pushdown::Transition
- Extended by:
- Loggability, Pluggability
- Defined in:
- lib/pushdown/transition.rb
Overview
A transition in a Pushdown automaton
Defined Under Namespace
Classes: Pop, Push, Replace, Switch
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
The name of the transition; mostly for human consumption.
Class Method Summary collapse
-
.inherited(subclass) ⇒ Object
Inheritance hook – enable instantiation.
Instance Method Summary collapse
-
#apply(stack) ⇒ Object
Return a state
stackafter the transition has been applied. -
#initialize(name) ⇒ Transition
constructor
Create a new Transition with the given
name. -
#type_name ⇒ Object
Return the transition’s type as a lowercase Symbol, such as that specified in transition declarations.
Constructor Details
#initialize(name) ⇒ Transition
Create a new Transition with the given name.
39 40 41 |
# File 'lib/pushdown/transition.rb', line 39 def initialize( name ) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
The name of the transition; mostly for human consumption
50 51 52 |
# File 'lib/pushdown/transition.rb', line 50 def name @name end |
Class Method Details
.inherited(subclass) ⇒ Object
Inheritance hook – enable instantiation.
29 30 31 32 33 34 35 |
# File 'lib/pushdown/transition.rb', line 29 def self::inherited( subclass ) super subclass.public_class_method( :new ) if (( type_name = subclass.name&.sub( /.*::/, '' )&.downcase )) Pushdown::State.register_transition( type_name ) end end |
Instance Method Details
#apply(stack) ⇒ Object
Return a state stack after the transition has been applied.
54 55 56 57 |
# File 'lib/pushdown/transition.rb', line 54 def apply( stack ) raise NotImplementedError, "%p doesn't implement required method #%p" % [ self.class, __method__ ] end |
#type_name ⇒ Object
Return the transition’s type as a lowercase Symbol, such as that specified in transition declarations.
62 63 64 65 |
# File 'lib/pushdown/transition.rb', line 62 def type_name class_name = self.class.name or return :anonymous return class_name.sub( /.*::/, '' ).downcase.to_sym end |