(1..5).to_a # [1, 2, 3, 4, 5] (inclusive)
(1...5).to_a # [1, 2, 3, 4] (exclusive)
('a'..'e').to_a
(1..) # endless range
(..10) # beginless range
(1..10).step(3).to_a # [1, 4, 7, 10]
(1..10) % 3 # ArithmeticSequence
(1..10).include?(5); (1..10).cover?(3..4); (1..10).sum; (1..10).size
(1.0..2.0).include?(1.5) # float ranges (can't iterate)
arr[2..]; arr[..-2] # slicing with ranges
case age when 0..12 then "child" end
(Date.today..Date.today + 7).each { |d| puts d }
12.2 Sets
require "set" # autoloaded in Ruby 3.2+; Set becomes core in Ruby 4.0
s = Set[1, 2, 3]
s << 2 # no duplicates
s.add?(4) # returns nil if already present
s.include?(1)
s | Set[5]; s & Set[1, 9]; s - Set[1]; s ^ Set[1, 10]
s.subset?(Set[1, 2, 3, 4]); s.superset?(Set[1]); s.disjoint?(Set[9])
[1, 1, 2].to_set