Skip to content

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

instance method

Integer#to_r

() -> ::Rational
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.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0