Module: TTY::Equatable
- Included in:
- Table, Table::ColumnSet, Vector
- Defined in:
- lib/tty/support/equatable.rb
Overview
Make it easy to define equality and hash methods.
Defined Under Namespace
Modules: Methods
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.
32 33 34 |
# File 'lib/tty/support/equatable.rb', line 32 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.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/tty/support/equatable.rb', line 16 def self.included(base) super base.extend(self) base.class_eval do define_comparison_attrs include Methods define_methods end self 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.
43 44 45 46 |
# File 'lib/tty/support/equatable.rb', line 43 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.
53 54 55 56 |
# File 'lib/tty/support/equatable.rb', line 53 def inherited(subclass) super subclass.instance_variable_set(:@comparison_attrs, comparison_attrs.dup) end |