From 1deeb1efc5cdc9fe31ebc796764dac4fb4b23b1f Mon Sep 17 00:00:00 2001 From: Carl Allen Date: Tue, 23 Mar 2021 10:23:38 -0500 Subject: [PATCH] Make Spaceship and comparison Numeric safe Rails 6.1 uses the spaceship operator against 0 to verify numerical-ness, but this doesn't work. --- lib/alchemist/measurement.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/alchemist/measurement.rb b/lib/alchemist/measurement.rb index 5937bae..27a287b 100644 --- a/lib/alchemist/measurement.rb +++ b/lib/alchemist/measurement.rb @@ -84,11 +84,13 @@ def to_f end def <=> other - to_f <=> other.to(unit_name).to_f + other = other.to(unit_name) unless other.is_a?(Numeric) + to_f <=> other.to_f end def == other - to_f <=> other.to(unit_name).to_f + other = other.to(unit_name) unless other.is_a?(Numeric) + to_f <=> other.to_f end def types