i=10
case i
when 1..9
puts "not 10"
when 10
puts "it is 10"
end
output: "it is 10"
String matching:
input="hello"
case input
when "hello world"
puts "hello world"
when "hell"
puts "heaven"
when /hell/
puts "hell inside"
end
output: "hell inside"
i=10
case i
when 1..9
puts "not 10"
when 10
puts "it is 10"
end
output: "it is 10"
input="hello"
case input
when "hello world"
puts "hello world"
when "hell"
puts "heaven"
when /hell/
puts "hell inside"
end
output: "hell inside"