/(a)
public
Returns the quotient of this value and a.
r = Rational(3,4)
r / 2
r / 2.0
r / Rational(1,2)
Show source
def / (a)
if a.kind_of?(Rational)
num = @numerator * a.denominator
den = @denominator * a.numerator
Rational(num, den)
elsif a.kind_of?(Integer)
raise ZeroDivisionError, "division by zero" if a == 0
self / Rational.new!(a, 1)
elsif a.kind_of?(Float)
Float(self) / a
else
x, y = a.coerce(self)
x / y
end
end