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: idable.rb
    path of file: ./repos/mongo-ruby-driver/lib/mongo/operation/shared
    
    the code of the file until where you have to start completion: # frozen_string_literal: true
# rubocop:todo all

# Copyright (C) 2018-2020 MongoDB Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable 
    
      def id(doc)
        doc.respond_to?(:id) ? doc.id : (doc['_id'] || doc[:_id])
      end

      def has_id?(doc)
        !!id(doc)
      end

      def ensure_ids(documents)
        @ids = []
        documents.collect do |doc|
          doc_with_id = has_id?(doc) ? doc : doc.merge(_id: id_generator.generate)
          @ids << id(doc_with_id)
          doc_with_id
        end
      end
    end
  end