Module: Kvom::ModelIdentity
- Included in:
- Kvom::Model::Base
- Defined in:
- lib/kvom/model_identity.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#==(comparison_object) ⇒ Object
Returns true if
comparison_object
is the same exact object, orcomparison_object
is of the same type andself
has an ID and it is equal tocomparison_object.id
. -
#eql?(comparison_object) ⇒ Boolean
Delegates to ==.
-
#hash ⇒ Object
Delegates to id in order to allow two records of the same type and id to work with something like: [ Person.find(1), Person.find(2), Person.find(3) ] & [ Person.find(1), Person.find(4) ] # => [ Person.find(1) ].
Instance Method Details
#==(comparison_object) ⇒ Object
Returns true if comparison_object
is the same exact object, or comparison_object
is of the same type and self
has an ID and it is equal to comparison_object.id
.
8 9 10 11 |
# File 'lib/kvom/model_identity.rb', line 8 def ==(comparison_object) comparison_object.equal?(self) || (comparison_object.instance_of?(self.class) && comparison_object.id == id) end |
#eql?(comparison_object) ⇒ Boolean
Delegates to ==
14 15 16 |
# File 'lib/kvom/model_identity.rb', line 14 def eql?(comparison_object) self == (comparison_object) end |
#hash ⇒ Object
Delegates to id in order to allow two records of the same type and id to work with something like:
[ Person.find(1), Person.find(2), Person.find(3) ] & [ Person.find(1), Person.find(4) ] # => [ Person.find(1) ]
20 21 22 |
# File 'lib/kvom/model_identity.rb', line 20 def hash id.hash end |