Name

case Statement

Synopsis

case expression
[when expression[, expression...] [then]
code]...
[else
code]
end

Compares the expression specified by case and that specified by when using the === operator and executes the code of the when clause that matches. The expression specified by the when clause is evaluated as the left operand. If no when clauses match, case executes the code of the else clause. A when statement’s expression is separated from code by the reserved word then, a newline, or a semicolon.

Get Ruby in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.