Symbols and Ranges

Lesson 10 of 20

Symbols are Ruby's lightweight names; ranges are number spans — small types you will use every day.

The big picture

Small types, big habits

Two tiny types appear everywhere in Ruby code: symbols name things, ranges describe spans of values.

Symbols: :word

A symbol is a lightweight constant name — the same :word is always the same object.

Where symbols shine

Hash keys and method names are symbols under the hood: :name, :level, :each.

Ranges: 1..5

A range is a span of values with a start and an end — numbers, letters, more.

Two dots vs three

1..5 includes 5; 1...5 stops at 4 — the extra dot leaves the end out.