Module: MiniMongo::Comparable

Includes:
Comparable
Included in:
Base
Defined in:
lib/mini_mongo/comparable.rb

Instance Method Summary collapse

Instance Method Details

#<=>(other) ⇒ Integer

Default comparison is via the string version of the id.

Examples:

Compare two documents.

person <=> other_person

Parameters:

  • other (Document)

    The document to compare with.

Returns:

  • (Integer)

    -1, 0, 1.



13
14
15
# File 'lib/mini_mongo/comparable.rb', line 13

def <=>(other)
  attributes["id"] <=> other.attributes["id"]
end

#===(other) ⇒ true, false

Performs class equality checking.

Examples:

Compare the classes.

document === other

Parameters:

  • other (Document, Object)

    The other object to compare with.

Returns:

  • (true, false)

    True if the classes are equal, false if not.



25
26
27
# File 'lib/mini_mongo/comparable.rb', line 25

def ===(other)
  other.class == Class ? self.class === other : self == other
end

#eql?(other) ⇒ true, false

Delegates to ==. Used when needing checks in hashes.

Examples:

Perform equality checking.

document.eql?(other)

Parameters:

  • other (Document, Object)

    The object to check against.

Returns:

  • (true, false)

    True if equal, false if not.



37
38
39
# File 'lib/mini_mongo/comparable.rb', line 37

def eql?(other)
  self == (other)
end