Class: Moody::State
- Inherits:
-
Object
- Object
- Moody::State
- Defined in:
- lib/moody.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Instance Method Summary collapse
- #enter ⇒ Object
-
#initialize(context) ⇒ State
constructor
A new instance of State.
- #leave ⇒ Object
- #switch_to(next_state) ⇒ Object
Constructor Details
#initialize(context) ⇒ State
Returns a new instance of State.
33 34 35 |
# File 'lib/moody.rb', line 33 def initialize(context) @context = context end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
31 32 33 |
# File 'lib/moody.rb', line 31 def context @context end |
Instance Method Details
#enter ⇒ Object
46 47 |
# File 'lib/moody.rb', line 46 def enter end |
#leave ⇒ Object
43 44 |
# File 'lib/moody.rb', line 43 def leave end |
#switch_to(next_state) ⇒ Object
37 38 39 40 41 |
# File 'lib/moody.rb', line 37 def switch_to(next_state) context.state.leave if context.state.respond_to?(:leave) context.state = next_state.new(context) context.state.enter if context.state.respond_to?(:enter) end |