uses several ranges to test values. A range is a range of numbers. : with case « Range « Ruby






uses several ranges to test values. A range is a range of numbers.


scale = 8
case scale
  when    0: puts "lowest"
  when 1..3: puts "medium-low"
  when 4..5: puts "medium"
  when 6..7: puts "medium-high"
  when 8..9: puts "high"
  when   10: puts "highest"
  else       puts "off scale"
end
# => high

 








Related examples in the same category