mruby-complex: provide Complex#<=> in Ruby

This commit is contained in:
Yukihiro "Matz" Matsumoto
2024-06-16 15:14:22 +09:00
parent 3b9aec90dd
commit 75de002058
+7
View File
@@ -19,6 +19,13 @@ class Complex < Numeric
Complex(-real, -imaginary)
end
def <=>(other)
return nil unless other.kind_of?(Numeric)
self.to_f <=> other.to_f
rescue
nil
end
def abs
Math.hypot imaginary, real
end