From 75de0020587c8b91616e7e81f3c39c9cdc1b362a Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Sun, 16 Jun 2024 15:14:22 +0900 Subject: [PATCH] mruby-complex: provide Complex#<=> in Ruby --- mrbgems/mruby-complex/mrblib/complex.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mrbgems/mruby-complex/mrblib/complex.rb b/mrbgems/mruby-complex/mrblib/complex.rb index e341efc5d..44b218024 100644 --- a/mrbgems/mruby-complex/mrblib/complex.rb +++ b/mrbgems/mruby-complex/mrblib/complex.rb @@ -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