My understanding is that the if
statements at the end of the line are evaluated before the code at the front of the line:
'never shown' if (false)
And assignment is possible in an if
statement.
'shown' if (value = 'dave is king')
value #=> "dave is king"
And, when a variable that doesn't exist is assigned to, it is created. There is no need for it to exist beforehand. Is this true?
If all these assumptions are true, why does this fail?
error_array << error if (error = import_value(value))
#=> undefined local variable or method `error' for
It assigned to error before the array push right? I want to understand when things are evaluated.
This one does work:
if (error = import_value(value))
error_array << error
end
Now I'm really confused.