Class: Nay::State
- Inherits:
-
Object
- Object
- Nay::State
- Defined in:
- lib/nay/state.rb
Overview
Basic stack implementation for storing a basic state machine flow.
Constant Summary collapse
- DEFAULT =
:default
Instance Attribute Summary collapse
-
#stack ⇒ Object
readonly
Returns the value of attribute stack.
Instance Method Summary collapse
- #current ⇒ Object
-
#initialize ⇒ State
constructor
A new instance of State.
- #pop ⇒ Object
- #push(state) ⇒ Object
Constructor Details
#initialize ⇒ State
Returns a new instance of State.
10 11 12 |
# File 'lib/nay/state.rb', line 10 def initialize @stack = [] end |
Instance Attribute Details
#stack ⇒ Object (readonly)
Returns the value of attribute stack.
8 9 10 |
# File 'lib/nay/state.rb', line 8 def stack @stack end |
Instance Method Details
#current ⇒ Object
14 15 16 |
# File 'lib/nay/state.rb', line 14 def current stack.last || DEFAULT end |
#pop ⇒ Object
22 23 24 |
# File 'lib/nay/state.rb', line 22 def pop stack.pop end |
#push(state) ⇒ Object
18 19 20 |
# File 'lib/nay/state.rb', line 18 def push(state) stack.push(state) end |