Avoid direct access to instance variables in `rational.rb`.

parent 912d2363
......@@ -72,14 +72,14 @@ class Rational < Numeric
def <=>(rhs)
case rhs
when Fixnum
return @numerator <=> rhs if @denominator == 1
return numerator <=> rhs if denominator == 1
rhs = Rational(rhs)
when Float
return to_f <=> rhs
end
case rhs
when Rational
(@numerator * rhs.denominator - @denominator * rhs.numerator) <=> 0
(numerator * rhs.denominator - denominator * rhs.numerator) <=> 0
when Numeric
return rhs <=> self
else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment