instance method
Time#to_r
() -> ::Rational
to_r → rational
time.c
View on GitHub ↗
static VALUE
time_to_r(VALUE time)
{
struct time_object *tobj;
VALUE v;
GetTimeval(time, tobj);
v = rb_time_unmagnify_to_rational(tobj->timew);
if (!RB_TYPE_P(v, T_RATIONAL)) {
v = rb_Rational1(v);
}
return v;
}
Returns the value of self as a Rational exact number of Epoch seconds;
Example
Time.now.to_r # => (16571402750320203/10000000)