You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: state_collection.rb
    path of file: ./repos/state_machines/lib/state_machines
    
    the code of the file until where you have to start completion: module StateMachines
  # Represents a collection of states in a state machine
  class StateCollection < NodeCollection
    def initialize(machine) #:nodoc:
      super(machine, index: [:name, :qualified_name, :value])
    end

    # Determines whether the given object is in a specific state.  If the
    # object's current value doesn't match the state, then this
    
    def by_priority
      order = select { |state| state.initial }.map { |state| state.name }

      machine.events.each { |event| order += event.known_states }
      order += select { |state| state.context_methods.any? }.map { |state| state.name }
      order += keys(:name) - machine.callbacks.values.flatten.flat_map(&:known_states)
      order += keys(:name)

      order.uniq!
      order.map! { |name| self[name] }
      order
    end