Name

if Statement

Synopsis

if conditional [then]
code
[elsif conditional [then]
code]...
[else
code]
end

Executes code if the conditional is true. True is interpreted as anything that isn’t false or nil. If the conditional isn’t true, code specified in the else clause is executed. An if expression’s conditional is separated from code by the reserved word then, a newline, or a semicolon. The reserved word if can be used as a statement modifier.

code if conditional

Executes code if conditional is true.

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.