All Ruby expressions return a result : case « Statement « Ruby
- Ruby
- Statement
- case
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