Name
Rational — Rational number class
Synopsis
When this library is loaded with
require
, the **
operator method
of the Integer
class can handle rational numbers,
and the following methods are added to the Integer
class:
to_r
Converts a number to a rational number
lcm
Returns the least common multiple
gcd
R
eturns the greatest common divisor
Required Library
require ‘rational’
Inherited Class
Numeric
Class Methods
Rational(
a
,
b
)
Rational::new(
a
,
b
)
Creates a rational number object. The former,
Rational(
a
,
b
)
, is recommended.
Get Ruby in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.