Module: Equatable
- Defined in:
- lib/equatable.rb,
lib/equatable/version.rb
Overview
Make it easy to define equality and hash methods.
Defined Under Namespace
Modules: Methods
Constant Summary collapse
- VERSION =
"0.7.0"
Instance Attribute Summary collapse
-
#comparison_attrs ⇒ Array<Symbol>
readonly
private
Holds all attributes used for comparison.
Class Method Summary collapse
-
.included(base) ⇒ self
private
Hook into module inclusion.
Instance Method Summary collapse
-
#attr_reader(*args) ⇒ undefined
Objects that include this module are assumed to be value objects.
-
#inherited(subclass) ⇒ Object
private
Copy the comparison_attrs into the subclass.
Instance Attribute Details
#comparison_attrs ⇒ Array<Symbol> (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Holds all attributes used for comparison.
29 30 31 |
# File 'lib/equatable.rb', line 29 def comparison_attrs @comparison_attrs end |
Class Method Details
.included(base) ⇒ self
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Hook into module inclusion.
15 16 17 18 19 20 21 22 |
# File 'lib/equatable.rb', line 15 def self.included(base) super base.extend(self) base.class_eval do include Methods define_methods end end |
Instance Method Details
#attr_reader(*args) ⇒ undefined
Objects that include this module are assumed to be value objects. It is also assumed that the only values that affect the results of equality comparison are the values of the object’s attributes.
40 41 42 43 |
# File 'lib/equatable.rb', line 40 def attr_reader(*args) super comparison_attrs.concat(args) end |
#inherited(subclass) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Copy the comparison_attrs into the subclass.
50 51 52 53 |
# File 'lib/equatable.rb', line 50 def inherited(subclass) super subclass.instance_variable_set(:@comparison_attrs, comparison_attrs.dup) end |