module Mongoid::Equality
This module contains the behavior of Mongoid’s clone/dup of documents.
Public Instance Methods
<=>(other)
click to toggle source
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.
# File lib/mongoid/equality.rb, line 20 def <=>(other) attributes["_id"].to_s <=> other.attributes["_id"].to_s end
==(other)
click to toggle source
Performs equality checking on the document ids. For more robust equality checking please override this method.
@example Compare for equality.
document == other
@param [ Document
| Object
] other The other object to compare with.
@return [ true | false ] True if the ids are equal, false if not.
# File lib/mongoid/equality.rb, line 33 def ==(other) self.class == other.class && attributes["_id"] == other.attributes["_id"] end
eql?(other)
click to toggle source
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.
# File lib/mongoid/equality.rb, line 46 def eql?(other) self == (other) end