Method: Time#to_r

Defined in:
time.c

#to_rObject

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

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

Related: Time#to_f, Time#to_i.



3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
# File 'time.c', line 3843

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;
}