Move Object#(Rational|Complex) to Kernel

This commit is contained in:
KOBAYASHI Shuji
2019-05-18 18:31:55 +09:00
parent 89d2926415
commit 6c9c189e4b
2 changed files with 13 additions and 9 deletions
+6 -4
View File
@@ -107,7 +107,7 @@ class Complex < Numeric
def polar
[abs, arg]
end
def real?
false
end
@@ -147,8 +147,10 @@ class << Complex
alias_method :rect, :rectangular
end
def Complex(real, imaginary = 0)
Complex.rectangular(real, imaginary)
module Kernel
def Complex(real, imaginary = 0)
Complex.rectangular(real, imaginary)
end
end
[Fixnum, Float].each do |cls|
@@ -165,4 +167,4 @@ end
end
end
end
end
end
+7 -5
View File
@@ -75,11 +75,13 @@ class Numeric
end
end
def Rational(numerator = 0, denominator = 1)
a = numerator
b = denominator
a, b = b, a % b until b == 0
Rational._new(numerator.div(a), denominator.div(a))
module Kernel
def Rational(numerator = 0, denominator = 1)
a = numerator
b = denominator
a, b = b, a % b until b == 0
Rational._new(numerator.div(a), denominator.div(a))
end
end
[:+, :-, :*, :/, :<=>, :==, :<, :<=, :>, :>=].each do |op|