Fractional::Fraction(T, U)
Inherits Comparable < Comparable < Comparable < Comparable < Fractional::Arithmetic < Struct < Value < Object
This is the star of the show, as it were.
A Fraction is really a container of (technically) any two values of any two types. This framework was chosen to allow for the ability to represent different values for any given numer-/denominator, including other fractions. This would not be possible without an extremly complicated inheritance system otherwise, since all structs ultimately inherit from the same memory address, meaning that a struct would refer to itself, causing lots of recursion issues.
This setup ensures that, no matter how deep you decide to nest a fraction, it won't be a nightmare to fight with typing.
Constructors
The "true" constructor for the type; returns a new Fraction(T, U)
with the given numerator and denominator
DEPRECATED: this is not intended to be called directly by the end-user.
End-users should use Fractional.new or frac(numerator, denominator)
for creating regular fractions.
Instance methods
Returns the result of multiplying self and other as fractions.
Returns the result of multiplying a fraction by an integer.
Returns the product of self and other cast to Fraction.
Returns a fraction whose numerator and denominator are the result of exponentiating
self's numerator and denominator.
Returns the result of adding self and other as fractions.
Returns the result of adding a fraction to an integer.
Returns the sum of self and other cast to Fraction.
Returns the result of subtracting self and other as fractions.
Returns the result of subtracting a fraction from an integer.
Returns the difference of self and other cast to Fraction.
Returns the result of dividing self and other as fractions (so really, multiplying by the reciprocal).
Returns the result of dividing a fraction with an integer (so really, multiplying by 1 over the integer)
Returns the quotient of self and other cast to Fraction.
Compares self with other of type BigRational.
Returns -1 if self is less than other, 1 if self is greater than other,
0 if self is the same as other, and nil otherwise.
Compares self with other of type Int.
Returns -1 if self is less than other, 1 if self is greater than other,
0 if self is the same as other, and nil otherwise.
Compares self with other of type Float.
Returns -1 if self is less than other, 1 if self is greater than other,
0 if self is the same as other, and nil otherwise.
Compares self with other of type Fraction.
Returns -1 if self is less than other, 1 if self is greater than other,
0 if self is the same as other, and nil otherwise.
Returns the reciprocal of self.
Returns the self in simplest terms.
Returns self's sign as an Int32
Returns the value of the numerator divided by the denominator as a Float64.
Returns the value of the numerator divided by the denominator as a Float32.
Returns the value of the numerator divided by the denominator as a Float64.
If self can be reduced to simplest terms with a denominator of 1,
return that fraction's numerator. Otherwise, return nil.
Writes a String representation of self to io.
Returns a String representation of self.