Module: MLB::ComparableByAttribute Private
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Provides comparison behavior for model classes by a specified attribute. Handles nil values gracefully by placing them at the end when sorting.
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer?
Compares this object with another by the comparable attribute.
Instance Method Details
#<=>(other) ⇒ Integer?
Compares this object with another by the comparable attribute
21 22 23 24 25 26 27 28 |
# File 'lib/mlb/comparable_by_attribute.rb', line 21 def <=>(other) return nil unless other.is_a?(self.class) || is_a?(other.class) compare_values( public_send(comparable_attribute), other.public_send(comparable_attribute) ) end |