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

parent 912d2363
...@@ -72,14 +72,14 @@ class Rational < Numeric ...@@ -72,14 +72,14 @@ class Rational < Numeric
def <=>(rhs) def <=>(rhs)
case rhs case rhs
when Fixnum when Fixnum
return @numerator <=> rhs if @denominator == 1 return numerator <=> rhs if denominator == 1
rhs = Rational(rhs) rhs = Rational(rhs)
when Float when Float
return to_f <=> rhs return to_f <=> rhs
end end
case rhs case rhs
when Rational when Rational
(@numerator * rhs.denominator - @denominator * rhs.numerator) <=> 0 (numerator * rhs.denominator - denominator * rhs.numerator) <=> 0
when Numeric when Numeric
return rhs <=> self return rhs <=> self
else 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