class ActiveSupport::Callbacks::CallbackChain

def compile(type)

def compile(type)
  if type.nil?
    @all_callbacks || @mutex.synchronize do
      final_sequence = CallbackSequence.new
      @all_callbacks ||= @chain.reverse.inject(final_sequence) do |callback_sequence, callback|
        callback.apply(callback_sequence)
      end
    end
  else
    @single_callbacks[type] || @mutex.synchronize do
      final_sequence = CallbackSequence.new
      @single_callbacks[type] ||= @chain.reverse.inject(final_sequence) do |callback_sequence, callback|
        type == callback.kind ? callback.apply(callback_sequence) : callback_sequence
      end
    end
  end
end