Ruby Rational Functions
EditRocket provides the following information on Rational functions in the Ruby source code builder.
abs() - Returns the absolute value.
coerce(other) -
divmod(other) - Returns the quotient and remainder.
hash() - Returns a hash code for the object.
inspect() - "Returns a reconstructable string representation:"
new!(num, den = 1) - "Implements the constructor. This method does not reduce to lowest terms or check for division by zero. Therefore #Rational() should be preferred in normal use."
new(num, den) - This method is actually private.
power2(other) -
reduce(num, den = 1) - Reduces the given numerator and denominator to their lowest terms. Use Rational() instead.
to_f() - Converts the rational to a Float.
to_i() - "Converts the rational to an Integer. Not the nearest integer, the truncated integer. Study the following example carefully:"
to_r() - Returns self.
to_s() - Returns a string representation of the rational number.