Module: CompareBy::InstanceMethods
- Defined in:
- lib/compare_by.rb
Instance Method Summary collapse
Instance Method Details
#<=>(other) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/compare_by.rb', line 12 def <=>(other) attrs = self.class.class_variable_get(:@@comparison_attrs) if attrs vals = attrs.map { |attr_name| send(attr_name) } other_vals = attrs.map { |attr_name| other.send(attr_name) } vals <=> other_vals else super end end |
#eql?(other) ⇒ Boolean
24 25 26 |
# File 'lib/compare_by.rb', line 24 def eql?(other) self == other end |
#hash ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/compare_by.rb', line 28 def hash attrs = self.class.class_variable_get(:@@comparison_attrs) if attrs attrs.map do |attr_name| send(attr_name) end.hash else super end end |