0Pricing
Ruby Academy · Lesson

Creating Ranges

Inclusive and exclusive ranges.

What Is a Range?

A Range represents a sequence between a start and an end value. Write it with two dots: 1..5.

r = 1..5
puts r
puts r.class

Inclusive Ranges

Two dots make an inclusive range that includes the end value. 1..5 covers 1, 2, 3, 4, 5.

puts (1..5).to_a.inspect

All lessons in this course

  1. Creating Ranges
  2. The Enumerable Module
  3. map, select, reject
  4. reduce and each_with_object
← Back to Ruby Academy