Skip to content

End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Integer#to_r

int.to_r → rational

Returns the value as a rational.

Example
1.to_r        #=> (1/1)
(1<<64).to_r  #=> (18446744073709551616/1)
See also #to_int #to_s #to_i #truncate also in 4.1 · 4.0 · 3.4 · 3.3 · 3.1 · 3.0