Shorten compare_values case statements

This commit is contained in:
Michael Miller 2024-01-27 11:25:25 -07:00
parent 556d4783bf
commit 526a998e41
No known key found for this signature in database
GPG key ID: 32B47AE8F388A1FF

View file

@ -45,23 +45,14 @@ module Spectator
when Range when Range
# Ranges can only be matched against if their right side is comparable. # Ranges can only be matched against if their right side is comparable.
# Ensure the right side is comparable, otherwise compare directly. # Ensure the right side is comparable, otherwise compare directly.
if b.is_a?(Comparable(typeof(b))) return a === b if b.is_a?(Comparable(typeof(b)))
a === b a == b
else
a == b
end
when Tuple, Array when Tuple, Array
if b.is_a?(Tuple) || b.is_a?(Array) return compare_tuples(a, b) if b.is_a?(Tuple) || b.is_a?(Array)
compare_tuples(a, b) a === b
else
a === b
end
when NamedTuple, Hash when NamedTuple, Hash
if b.is_a?(NamedTuple) || b.is_a?(Hash) return compare_named_tuples(a, b) if b.is_a?(NamedTuple) || b.is_a?(Hash)
compare_named_tuples(a, b) a === b
else
a === b
end
else else
a === b a === b
end end