The following ruby statement will result in x
being "defined" (i.e. defined(x)
returning "local-variable"
even if it is undefined prior to execution of this code and even though the assignment is not performed:
x = 1 if false
Specifically, the x
local variable will be set to nil
. The behavior is similar for never-executed assignments subject to while false
and until false
clauses. You can verify this in either irb or running ruby on some code fragment.
My question is twofold:
- Is this behavior documented anywhere?
- Is there a rationale for this behavior documented anywhere?