123456789_123456789_123456789_123456789_123456789_

Module: Mongoid::Equality

Relationships & Source Files
Namespace Children
Modules:
Extension / Inclusion / Inheritance Descendants
Included In:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, ActiveSupport::Concern
Defined in: lib/mongoid/equality.rb

Overview

This module contains the behavior of Mongoid’s clone/dup of documents.

Instance Method Summary

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:

[ GitHub ]

  
# File 'lib/mongoid/equality.rb', line 18

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.

Examples:

Compare for equality.

document == other

Parameters:

Returns:

  • (true | false)

    True if the ids are equal, false if not.

[ GitHub ]

  
# File 'lib/mongoid/equality.rb', line 33

def ==(other)
  self.class == other.class &&
    attributes['_id'] == other.attributes['_id']
end

#eql?(other) ⇒ true | false

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

Examples:

Perform equality checking.

document.eql?(other)

Parameters:

Returns:

  • (true | false)

    True if equal, false if not.

[ GitHub ]

  
# File 'lib/mongoid/equality.rb', line 46

def eql?(other)
  self == other
end