case...when with range : case « Statement « Ruby






case...when with range


#!/usr/bin/env ruby

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

 








Related examples in the same category

1.Here's the general format of the Ruby case statement:
2.Using the case Statement
3.If vs Case
4.use exculsive ranges in case statements
5.use a case statement to make an assignment, which omits the value to test
6.elsif and case
7.All Ruby expressions return a result
8.Case with regular expression