module MiniMongo module Comparable include ::Comparable # Default comparison is via the string version of the id. # # @example Compare two documents. # person <=> other_person # # @param [ Document ] other The document to compare with. # # @return [ Integer ] -1, 0, 1. def <=>(other) attributes["id"] <=> other.attributes["id"] end # Performs class equality checking. # # @example Compare the classes. # document === other # # @param [ Document, Object ] other The other object to compare with. # # @return [ true, false ] True if the classes are equal, false if not. def ===(other) other.class == Class ? self.class === other : self == other end # Delegates to ==. Used when needing checks in hashes. # # @example Perform equality checking. # document.eql?(other) # # @param [ Document, Object ] other The object to check against. # # @return [ true, false ] True if equal, false if not. def eql?(other) self == (other) end end end