Module: VectorNumber::NumericRefinements::CommutativeShuttle
- Defined in:
- lib/vector_number/numeric_refinements.rb
Overview
Note:
Currently only applies to Complex on 3.1, as other numeric classes rely on #coerce
.
Refinement module to provide a #<=> method that can work backwards.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Commutative #<=>.
Instance Method Details
#<=>(other) ⇒ Object
Commutative #<=>. Tries to call other <=> self if self <=> other returns nil
.
36 37 38 39 40 41 42 |
# File 'lib/vector_number/numeric_refinements.rb', line 36 def <=>(other) comparison = super return comparison if comparison || !other.respond_to?(:<=>) comparison = other <=> self -comparison if comparison end |