Module: Mongoid::Equality
Overview
This module contains the behavior of Mongoid’s clone/dup of documents.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer
Default comparison is via the string version of the id.
-
#==(other) ⇒ true | false
Performs equality checking on the document ids.
-
#eql?(other) ⇒ true | false
Delegates to ==.
Instance Method Details
#<=>(other) ⇒ Integer
Default comparison is via the string version of the id.
20 21 22 23 |
# File 'lib/mongoid/equality.rb', line 20 def <=>(other) return super unless other.is_a?(Mongoid::Equality) attributes["_id"].to_s <=> other.attributes["_id"].to_s end |
#==(other) ⇒ true | false
Performs equality checking on the document ids. For more robust equality checking please override this method.
34 35 36 37 |
# File 'lib/mongoid/equality.rb', line 34 def ==(other) self.class == other.class && attributes["_id"] == other.attributes["_id"] end |
#eql?(other) ⇒ true | false
Delegates to ==. Used when needing checks in hashes.
47 48 49 |
# File 'lib/mongoid/equality.rb', line 47 def eql?(other) self == (other) end |