Class: Rational

Inherits:
Numeric show all
Defined in:
mrbgems/mruby-rational/mrblib/rational.rb

Instance Method Summary collapse

Methods inherited from Numeric

#+@, #-@, #abs, #integer?, #negative?, #nonzero?, #positive?, #to_c, #to_r, #zero?

Methods included from Comparable

#<, #<=, #==, #>, #>=, #between?, #clamp

Instance Method Details

#<=>(other) ⇒ Object



10
11
12
13
14
15
# File 'mrbgems/mruby-rational/mrblib/rational.rb', line 10

def <=>(other)
  return nil unless other.kind_of?(Numeric)
  self.to_f <=> other.to_f
rescue
  nil
end

#inspectObject



2
3
4
# File 'mrbgems/mruby-rational/mrblib/rational.rb', line 2

def inspect
  "(#{to_s})"
end

#to_sObject



6
7
8
# File 'mrbgems/mruby-rational/mrblib/rational.rb', line 6

def to_s
  "#{numerator}/#{denominator}"
end