All Ruby expressions return a result : case « Statement « Ruby






All Ruby expressions return a result


# you assign the result of whichever inner block is executed directly to color.

fruit = "orange"
color = case fruit
  when "orange"
    "orange"
  when "apple"
    "green"
  when "banana"
    "yellow"
  else
    "unknown"
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.case...when with range
5.use exculsive ranges in case statements
6.use a case statement to make an assignment, which omits the value to test
7.elsif and case
8.Case with regular expression