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.
34 35 36 |
# File 'lib/moody.rb', line 34 def initialize(context) @context = context end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
32 33 34 |
# File 'lib/moody.rb', line 32 def context @context end |
Instance Method Details
#enter ⇒ Object
47 48 |
# File 'lib/moody.rb', line 47 def enter end |
#leave ⇒ Object
44 45 |
# File 'lib/moody.rb', line 44 def leave end |
#switch_to(next_state) ⇒ Object
38 39 40 41 42 |
# File 'lib/moody.rb', line 38 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 |