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.
1
Symbols: :word
A symbol is a lightweight constant name — the same :word is always the same object.
2
Where symbols shine
Hash keys and method names are symbols under the hood: :name, :level, :each.
3
Ranges: 1..5
A range is a span of values with a start and an end — numbers, letters, more.
4
Two dots vs three
1..5 includes 5; 1...5 stops at 4 — the extra dot leaves the end out.
Small types, big habits
Symbols: :word1A symbol is a lightweight constant name — the same :word is always the same object.
Where symbols shine2Hash keys and method names are symbols under the hood: :name, :level, :each.
Ranges: 1..53A range is a span of values with a start and an end — numbers, letters, more.
Two dots vs three41..5 includes 5; 1...5 stops at 4 — the extra dot leaves the end out.
4 building blocks make up Small types, big habits
Watch it run
Symbols and ranges running
A symbol prints without its colon; a range answers include? and walks itself with each.
spans.rb
1status =:active
2
3puts status
4puts status.class
5
6dice =1..6
7
8puts dice.include?(4)
9
10dice.eachdo|n|
11puts"roll #{n}"
12end
main
status gets the Symbol :active.
Memory
status= :active
Console
output appears as the program runs…
Step 1/18
Visualize
Is a number inside a range?
include? asks two questions in a row — both must say yes before the value counts as inside.
process decision input / output start / end
Practice
Match symbols and ranges
Click an expression, then click what it is to lock the pair.
6 conceptsTap a card to expand
?:namedrops into place
?"name"drops into place
?1..5drops into place
?1...5drops into place
?include?(3)drops into place
?to_adrops into place
Challenge
Predict the output
Identity check: two strings, two objects — but one symbol, forever the same.
identity.rb
1s =:ruby
2
3puts s.class
4puts s ==:ruby
5puts"ruby".object_id =="ruby".object_id
6puts:ruby.object_id ==:ruby.object_id
7
8r =1...4
9puts r.include?(4)
10puts r.to_a.length
Your predicted output — one line per console line
Hint: Every :ruby in your program is the same object, but each "ruby" literal is a fresh string with its own identity. And 1...4 excludes the endpoint, so 4 is not inside — only 1, 2, 3 are.
Recap
Key takeaways
Key takeaways5 takeaways
01
:name is a Symbol — an immutable name, always the same object.
02
Symbols are perfect hash keys; strings are for text you build and change.
03
1..5 includes both ends; 1...5 excludes the last number.
04
Ranges answer include?, expand with to_a and iterate with each.
05
A symbol prints without its colon: puts :active shows active.