-(a)
public
Returns the difference of this value and a. subtracted.
Examples:
r = Rational(3,4)
r - 1
r - 0.5
Show source
def - (a)
if a.kind_of?(Rational)
num = @numerator * a.denominator
num_a = a.numerator * @denominator
Rational(num - num_a, @denominator*a.denominator)
elsif a.kind_of?(Integer)
self - Rational.new!(a, 1)
elsif a.kind_of?(Float)
Float(self) - a
else
x, y = a.coerce(self)
x - y
end
end