Class: BabyBots::State
- Inherits:
-
Object
- Object
- BabyBots::State
- Defined in:
- lib/baby_bots/state.rb
Instance Attribute Summary collapse
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
Instance Method Summary collapse
- #add_transition(event, transition, &callback) ⇒ Object
-
#build(*args) ⇒ Object
the idea behind build is that you can call multiple :event :transition and the build method will parse them out and add them to state.
-
#initialize(state, table = {}) ⇒ State
constructor
A new instance of State.
Constructor Details
#initialize(state, table = {}) ⇒ State
Returns a new instance of State.
6 7 8 9 |
# File 'lib/baby_bots/state.rb', line 6 def initialize(state, table={}) @state = state @table = table end |
Instance Attribute Details
#state ⇒ Object (readonly)
Returns the value of attribute state.
4 5 6 |
# File 'lib/baby_bots/state.rb', line 4 def state @state end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
4 5 6 |
# File 'lib/baby_bots/state.rb', line 4 def table @table end |
Instance Method Details
#add_transition(event, transition, &callback) ⇒ Object
11 12 13 |
# File 'lib/baby_bots/state.rb', line 11 def add_transition(event, transition, &callback) @table[event] = transition end |
#build(*args) ⇒ Object
the idea behind build is that you can call multiple :event :transition and the build method will parse them out and add them to state
18 19 20 |
# File 'lib/baby_bots/state.rb', line 18 def build(*args) args.map {|k,v| add_transition(k, v) } end |