Module: Lutaml::Model::ComparableModel
- Included in:
- Serialize
- Defined in:
- lib/lutaml/model/comparable_model.rb
Overview
ComparableModel module provides functionality to compare and diff two objects of the same class, based on their attribute values.
Defined Under Namespace
Modules: ClassMethods Classes: DiffContext, Tree
Class Method Summary collapse
Instance Method Summary collapse
-
#eql?(other) ⇒ Boolean
(also: #==)
Checks if two objects are equal based on their attributes.
-
#hash ⇒ Integer
Generates a hash value for the object.
Class Method Details
.included(base) ⇒ Object
8 9 10 |
# File 'lib/lutaml/model/comparable_model.rb', line 8 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#eql?(other) ⇒ Boolean Also known as: ==
Checks if two objects are equal based on their attributes
15 16 17 18 19 20 |
# File 'lib/lutaml/model/comparable_model.rb', line 15 def eql?(other) other.class == self.class && self.class.attributes.all? do |attr, _| send(attr) == other.send(attr) end end |
#hash ⇒ Integer
Generates a hash value for the object
26 27 28 29 30 |
# File 'lib/lutaml/model/comparable_model.rb', line 26 def hash ([self.class] + self.class.attributes.map do |attr, _| send(attr).hash end).hash end |