This is what my buddy and super-specialist Junior Josh Chick had to say:
When Ruby sees the assignment, it initializes the variable in the current scope and sets it to nil. Since the assignment did not start, it did not update the value of foo.
If statements do not change the scope, how blocks do. This is also the most important difference between
for x in xs
and
xs.each { |x| }
Here is another example:
a = 123 if a
We cannot say if a
, because we never set a
, but Ruby sees a = 123
and initializes a
, then goes to if a
, at which point a
is nil
I would consider this a fad translator. Gary Bernhardt makes fun of him at wat ( https://www.destroyallsoftware.com/talks/wat ) with a = a
-Josh
Kori john roys
source share