From 7ce03e32b7b21ae7f095dbc23b23497143919b01 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Fri, 5 Feb 2021 21:42:42 +0900 Subject: Add `Complex#to_c` method. --- mrbgems/mruby-complex/mrblib/complex.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'mrbgems/mruby-complex') diff --git a/mrbgems/mruby-complex/mrblib/complex.rb b/mrbgems/mruby-complex/mrblib/complex.rb index 67f940865..26a3b206f 100644 --- a/mrbgems/mruby-complex/mrblib/complex.rb +++ b/mrbgems/mruby-complex/mrblib/complex.rb @@ -97,6 +97,10 @@ class Complex < Numeric end alias_method :rect, :rectangular + def to_c + self + end + def to_r raise RangeError.new "can't convert #{to_s} into Rational" unless imaginary.zero? Rational(real, 1) -- cgit v1.2.3