Class: Float

Inherits:
Object
  • Object
show all
Defined in:
lib/radix/rational.rb

Instance Method Summary collapse

Instance Method Details

#to_rRational

Adds a #to_r method to pre-1.9 ruby Rationals.

Returns:

  • (Rational)


303
304
305
306
307
308
# File 'lib/radix/rational.rb', line 303

def to_r
  n, f = to_s.split('.')
  d = (10 ** f.size).to_i
  n = (n.to_i * d) + f.to_i
  Rational(n, d) 
end