mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
mruby-complex: provide Complex#<=> in Ruby
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user