xxxxxxxxxx
# Example 1
value = "apple"
case value
when "apple"
puts "It's a fruit"
when "carrot"
puts "It's a vegetable"
else
puts "Unknown"
end
xxxxxxxxxx
case {condition}
when {option1}
#do something
when {option2}
#do something
else #default
#do something else
end
xxxxxxxxxx
case fruit
when 'Apple'
# something
when 'Banana' then puts 'Right' # only if it is one line
else #default
# something
end
xxxxxxxxxx
# Sample input
color = "green"
# Using case-when
case color
when "red"
puts "The color is red"
when "blue"
puts "The color is blue"
when "green"
puts "The color is green"
else
puts "The color is unknown"
end