Module: Shamu::Attributes::Equality
- Included in:
- Entities::Entity, Events::Message
- Defined in:
- lib/shamu/attributes/equality.rb
Overview
Override equality methods to support shallow comparison of attribute values for equality.
Add ignore_equality: true
to any Attributes::DSL#attribute that
shouldn’t be included in equality comparisons.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
True if the two objects are of the same type and attributes are all eql? to each other.
-
#hash ⇒ Integer
A hash computed from the attributes of the object.
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Returns true if the two objects are of the same type and attributes are all eql? to each other.
14 15 16 17 18 |
# File 'lib/shamu/attributes/equality.rb', line 14 def ==( other ) return true if other.object_id == object_id return false unless other.is_a?( self.class ) || is_a?( other.class ) attributes_eql?( other ) end |
#hash ⇒ Integer
Returns a hash computed from the attributes of the object.
22 23 24 25 26 |
# File 'lib/shamu/attributes/equality.rb', line 22 def hash self.class.attributes.map do |key, _| send( key ) end.hash end |