Module: Mongoid::Equality
- Included in:
- Composable
- Defined in:
- lib/mongoid/equality.rb
Overview
This module contains the behaviour of Mongoid’s clone/dup of documents.
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.
-
#===(other) ⇒ true, false
Performs class equality checking.
-
#eql?(other) ⇒ true, false
Delegates to ==.
Instance Method Details
#<=>(other) ⇒ Integer
Default comparison is via the string version of the id.
17 18 19 |
# File 'lib/mongoid/equality.rb', line 17 def <=>(other) 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.
32 33 34 35 |
# File 'lib/mongoid/equality.rb', line 32 def ==(other) self.class == other.class && attributes["_id"] == other.attributes["_id"] end |
#===(other) ⇒ true, false
Performs class equality checking.
47 48 49 |
# File 'lib/mongoid/equality.rb', line 47 def ===(other) other.class == Class ? self.class === other : self == other end |
#eql?(other) ⇒ true, false
Delegates to ==. Used when needing checks in hashes.
61 62 63 |
# File 'lib/mongoid/equality.rb', line 61 def eql?(other) self == (other) end |