Last Updated: February 25, 2016
·
2.912K
· lukasalexandre

Ruby Case on Ranges

Case statements in Ruby are pretty cool because we can use ANYTHING that responds to a tree equal operator, ===. One of those is Range.

age = rand(1..100)
p age

case age
when -Float::INFINITY..20
  puts "You're too young."
when 21..64
  puts "You're the right age."
when 65..Float::INFINITY
  puts "You're too old."
end