Class: Pushdown::Transition

Inherits:
Object
  • Object
show all
Extended by:
Loggability, Pluggability
Defined in:
lib/pushdown/transition.rb

Overview

A transition in a Pushdown automaton

Direct Known Subclasses

Pop, Push, Replace, Switch

Defined Under Namespace

Classes: Pop, Push, Replace, Switch

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#nameObject (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.

Raises:

  • (NotImplementedError)


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_nameObject

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