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: expectations.rb
    path of file: ./repos/steep/lib/steep
    
    the code of the file until where you have to start completion: module Steep
  class Expectations
    class Diagnostic < Struct.new(:start_position, :end_positio
    
    def to_yaml
      array = [] #: Array[{ "file" => String, "diagnostics" => Array[untyped] }]

      diagnostics.each_key.sort.each do |key|
        ds = diagnostics[key]
        array << {
          "file" => key.to_s,
          'diagnostics' => ds.sort_by(&:sort_key).map(&:to_hash)
        }
      end

      YAML.dump(array)
    end