Sha256: 507e7edbd1981d44af58cbb53a329e392429ab806f64ad40626ebe1575be13ef
Contents?: true
Size: 646 Bytes
Versions: 6
Compression:
Stored size: 646 Bytes
Contents
class StateHolder < SimpleDelegator def initialize(opts={}) initial_state_class = opts.fetch :initial_state_class initial_state = initial_state_class.new(self, nil) # Set current_state within SimpleDelegator super(initial_state) end def transition_to(new_state_class) current_state.send(:exit) set_new_state(new_state_class) current_state.send(:enter) end def set_new_state(new_state_class) new_state = new_state_class.new(self, current_state.class) self.current_state = new_state end def current_state __getobj__ end private def current_state=(state) __setobj__(state) end end
Version data entries
6 entries across 6 versions & 1 rubygems