What is the correct way to write a switch statement in Ruby?

Basic case when Syntax : The case when statement in Ruby is similar to a switch statement in other languages like JavaScript or C. Here’s a basic example:

value = 2

case value
when 1
  puts "One"
when 2
  puts "Two"
when 3
  puts "Three"
else
  puts "Not in range"
end

This checks value against multiple conditions and executes the corresponding block. The else acts like a default case.