Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

Time#to_r

() -> ::Rational
to_r → rational

Returns the value of self as a Rational exact number of Epoch seconds;

Example
Time.now.to_r # => (16571402750320203/10000000)

Related: Time#to_f, Time#to_i.

See also #to_i #to_s #to_f #to_time also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0