Integer Type
In this page:
Integer Type
Ruby's Integer type represents whole numbers of arbitrary size -- there's no fixed-width overflow like in many other languages, since Ruby automatically promotes to arbitrary precision as needed. Integer division truncates toward negative infinity. Every integer is an object, so you can call methods directly on a literal, like 5.times.
Note: Because integers are objects, you can call methods directly on a literal, like 3.even? or 5.times { ... }.
Example: Integer Type
x = 42
big = 123456789012345678901234567890
puts x.class
puts big
puts 7 / 2
puts 5.even?
Login to try C/C++/Java/PHP code in the editor
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: