Name
if Statement
Synopsis
ifconditional
[then]code
[elsifconditional
[then]code
]... [elsecode
] 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
ifconditional
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.