Commit 6c9c189e authored by KOBAYASHI Shuji's avatar KOBAYASHI Shuji

Move `Object#(Rational|Complex)` to `Kernel`

parent 89d29264
...@@ -107,7 +107,7 @@ class Complex < Numeric ...@@ -107,7 +107,7 @@ class Complex < Numeric
def polar def polar
[abs, arg] [abs, arg]
end end
def real? def real?
false false
end end
...@@ -147,8 +147,10 @@ class << Complex ...@@ -147,8 +147,10 @@ class << Complex
alias_method :rect, :rectangular alias_method :rect, :rectangular
end end
def Complex(real, imaginary = 0) module Kernel
Complex.rectangular(real, imaginary) def Complex(real, imaginary = 0)
Complex.rectangular(real, imaginary)
end
end end
[Fixnum, Float].each do |cls| [Fixnum, Float].each do |cls|
...@@ -165,4 +167,4 @@ end ...@@ -165,4 +167,4 @@ end
end end
end end
end end
end end
\ No newline at end of file
...@@ -75,11 +75,13 @@ class Numeric ...@@ -75,11 +75,13 @@ class Numeric
end end
end end
def Rational(numerator = 0, denominator = 1) module Kernel
a = numerator def Rational(numerator = 0, denominator = 1)
b = denominator a = numerator
a, b = b, a % b until b == 0 b = denominator
Rational._new(numerator.div(a), denominator.div(a)) a, b = b, a % b until b == 0
Rational._new(numerator.div(a), denominator.div(a))
end
end end
[:+, :-, :*, :/, :<=>, :==, :<, :<=, :>, :>=].each do |op| [:+, :-, :*, :/, :<=>, :==, :<, :<=, :>, :>=].each do |op|
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment