Files
mruby-mruby/mrbgems/mruby-rational/mrblib/rational.rb
T
2024-06-17 08:02:42 +09:00

23 lines
291 B
Ruby

class Rational < Numeric
def inspect
"(#{to_s})"
end
def to_s
"#{numerator}/#{denominator}"
end
def <=>(other)
return nil unless other.kind_of?(Numeric)
self.to_f <=> other.to_f
rescue
nil
end
end
class Numeric
def to_r
Rational(self, 1)
end
end