Sha256: df1eff5951981594711989e0d29c9a5f25150286b6abe25f2adbea8621e142ad

Contents?: true

Size: 1.06 KB

Versions: 4

Compression:

Stored size: 1.06 KB

Contents

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mini_mongo-0.1.0 lib/mini_mongo/comparable.rb
mini_mongo-0.0.4 lib/mini_mongo/comparable.rb
mini_mongo-0.0.3 lib/mini_mongo/comparable.rb
mini_mongo-0.0.2 lib/mini_mongo/comparable.rb