peter-murach/finite_machine — pull request #26 by reggieb (2014-09-26 07:34:57+00:00)
Title: Removes use of global instance to share Sync

Perhaps I'm being pedantic, but I always see the use of a class variables as a red flag.

The advantage of this modification are:

It means Sync.new is only called once. With the current version @@sync = Sync.new is called for each object that inherits from FinteMachine::StateMachine. That is, every time an object loads FiniteMachine::Threadable::InstanceMethods, @@sync is reset.

More importantly, if a class that inherits from FinteMachine::StateMachine modifies @@sync, every FiniteMachine::StateMachine will be affected by that change.

class FiniteMachine::StateMachine
def current_sync
@@sync
end
end

state_machine = FiniteMachine::StateMachine.new

state_machine.current_sync -----> Instance of Sync

class OtherStateMachine < FiniteMachine::StateMachine
@@sync = something_else
end

state_machine.current_sync -----> something_else