Class: StatePattern::State

Inherits:
Object
  • Object
show all
Defined in:
lib/state_pattern/state.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stateful, previous_state) ⇒ State

Returns a new instance of State.



4
5
6
7
8
# File 'lib/state_pattern/state.rb', line 4

def initialize(stateful, previous_state)
  @stateful = stateful
  @previous_state = previous_state
  enter
end

Instance Attribute Details

#previous_stateObject (readonly)

Returns the value of attribute previous_state.



3
4
5
# File 'lib/state_pattern/state.rb', line 3

def previous_state
  @previous_state
end

#statefulObject (readonly)

Returns the value of attribute stateful.



3
4
5
# File 'lib/state_pattern/state.rb', line 3

def stateful
  @stateful
end

Class Method Details

.state_methodsObject



10
11
12
# File 'lib/state_pattern/state.rb', line 10

def self.state_methods
  public_instance_methods - State.public_instance_methods
end

Instance Method Details

#enterObject



18
19
# File 'lib/state_pattern/state.rb', line 18

def enter
end

#exitObject



21
22
# File 'lib/state_pattern/state.rb', line 21

def exit
end

#transition_to(state_class) ⇒ Object



14
15
16
# File 'lib/state_pattern/state.rb', line 14

def transition_to(state_class)
  @stateful.transition_to(state_class)
end