**

**(other) Instance Public methods Exponentiate by other (1/3) ** 2 # => 1/9

+

rat + numeric â numeric Instance Public methods Performs addition. Rational(2, 3) + Rational(2, 3) #=> (4/3) Rational(900) + Rational(1) #=> (900/1) Rational(-2, 9) + Rational(-9, 2) #=> (-85/18) Rational(9, 8) + 4 #=> (41/8) Rational(20, 9) + 9.8 #=> 12.022222222222222

-

rat - numeric â numeric Instance Public methods Performs subtraction. Rational(2, 3) - Rational(2, 3) #=> (0/1) Rational(900) - Rational(1) #=> (899/1) Rational(-2, 9) - Rational(-9, 2) #=> (77/18) Rational(9, 8) - 4 #=> (23/8) Rational(20, 9) - 9.8 #=> -7.577777777777778

/ 2

rat / numeric â numeric Instance Public methods Performs division. Rational(2, 3) / Rational(2, 3) #=> (1/1) Rational(900) / Rational(1) #=> (900/1) Rational(-2, 9) / Rational(-9, 2) #=> (4/81) Rational(9, 8) / 4 #=> (9/32) Rational(20, 9) / 9.8 #=> 0.22675736961451246

<=>

rational numeric â -1, 0, +1 or nil Instance Public methods Performs comparison and returns -1, 0, or +1. nil is returned if the two values are incomparable. Rational(2, 3) <=> Rational(2, 3) #=> 0 Rational(5) <=> 5 #=> 0 Rational(2,3) <=> Rational(1,3) #=> 1 Rational(1,3) <=> 1 #=> -1 Rational(1,3) <=> 0.3 #=> 1

==

rat == object â true or false Instance Public methods Returns true if rat equals object numerically. Rational(2, 3) == Rational(2, 3) #=> true Rational(5) == 5 #=> true Rational(0) == 0.0 #=> true Rational('1/3') == 0.33 #=> false Rational('1/2') == '1/2' #=> false

as_json

as_json(*) Instance Public methods

ceil

rat.ceil â integerrat.ceil(precision=0) â rational Instance Public methods Returns the truncated value (toward positive infinity). Rational(3).ceil #=> 3 Rational(2, 3).ceil #=> 1 Rational(-3, 2).ceil #=> -1 decimal - 1 2 3 . 4 5 6 ^ ^ ^ ^ ^ ^ precision -3 -2 -1 0 +1 +2 '%f' % Rational('-123.456').ceil(+1) #=> "-123.400000" '%f' % Rational('-123.456').ceil(-1) #=> "-120.000000"

denominator

rat.denominator â integer Instance Public methods Returns the denominator (always positive). Rational(7).denominator #=> 1 Rational(7, 1).denominator #=> 1 Rational(9, -4).denominator #=> 4 Rational(-2, -10).denominator #=> 5 rat.numerator.gcd(rat.denominator) #=> 1

fdiv

rat.fdiv(numeric) â float Instance Public methods Performs division and returns the value as a float. Rational(2, 3).fdiv(1) #=> 0.6666666666666666 Rational(2, 3).fdiv(0.5) #=> 1.3333333333333333 Rational(2).fdiv(3) #=> 0.6666666666666666