def find_or_create(owner_class, *args, &block)
options = args.last.is_a?(Hash) ? args.pop : {}
name = args.first || :state
if owner_class.respond_to?(:state_machines) && machine = owner_class.state_machines[name]
if machine.owner_class != owner_class && (options.any? || block_given?)
machine = machine.clone
machine.initial_state = options[:initial] if options.include?(:initial)
machine.owner_class = owner_class
end
machine.instance_eval(&block) if block_given?
else
machine = new(owner_class, name, options, &block)
end
machine
end