Module: UnitMeasurements::Comparison
Overview
The UnitMeasurements::Comparison
mixin module is included in measurement classes to enable comparison operations (e.g., less than, equal to, greater than, etc.) between two measurements of the same unit group.
This module is included in the Measurement
class to allow comparison of two measurements.
Instance Method Summary collapse
-
#<=>(object) ⇒ Object
This method is used to compare the quantity of two measurements.
Instance Method Details
#<=>(object) ⇒ Object
This method is used to compare the quantity of two measurements. It implements the comparison logic based on the <=> method defined in the Comparable
module.
58 59 60 61 62 |
# File 'lib/unit_measurements/comparison.rb', line 58 def <=>(object) return nil unless object.is_a?(self.class) quantity <=> object.convert_to(unit.name).quantity end |