← Back to Ruby Course | Chapter 2: Variables & Types | Lesson 2 of 7

Integer Type

In this page:

  1. Integer Type

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

markup
x = 42
big = 123456789012345678901234567890

puts x.class
puts big
puts 7 / 2
puts 5.even?
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.