use a case statement to make an assignment, which omits the value to test : case « Statement « Ruby






use a case statement to make an assignment, which omits the value to test


temperature = 76

message = case
when (0...65) === temperature
  "Too cold!"
when (85...120) === temperature
  "Too hot!"
when (65...85) === temperature
  "Picnic time!"
else
  "Temperature out of reasonable range!"
end

puts message

 








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.case...when with range
5.use exculsive ranges in case statements
6.elsif and case
7.All Ruby expressions return a result
8.Case with regular expression