Module: Sequent::Core::Helpers::EqualSupport
- Included in:
- BaseCommand, Event, ValueObject
- Defined in:
- lib/sequent/core/helpers/equal_support.rb
Overview
You typically do not need to include this module in your classes. If you extend from Sequent::Core::ValueObject, Sequent::Core::Event or Sequent::Core::BaseCommand you will get this functionality for free.
Instance Method Summary collapse
Instance Method Details
#==(other) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/sequent/core/helpers/equal_support.rb', line 12 def ==(other) return false if other.nil? return false if self.class != other.class self.class.types.each_key do |name| self_value = send(name) other_value = other.send(name) if self_value.class == DateTime && other_value.class == DateTime # we don't care about milliseconds. If you know a better way of checking for equality please improve. return false unless self_value.iso8601 == other_value.iso8601 else return false unless self_value == other_value end end true end |
#eql?(other) ⇒ Boolean
37 38 39 |
# File 'lib/sequent/core/helpers/equal_support.rb', line 37 def eql?(other) self == other end |
#hash ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/sequent/core/helpers/equal_support.rb', line 29 def hash hash = 17 self.class.types.each_key do |name| hash = (hash * 31) + send(name).hash end hash end |