|
|
|
|
|
by elcapitan
3619 days ago
|
|
I like the feature, but just for understanding, will the assignment always be truthy if any of the assigned variables are set? The example is branch1 =
if (foo, bar = %w[foo bar])
'truthy'
else
'falsey'
end
branch2 =
if (foo, bar = nil)
'truthy'
else
'falsey'
end
branch1 # => "truthy"
branch2 # => "falsey"
What about branch3 =
if (foo, bar = ['foo', nil])
'truthy'
else
'falsey'
end
?
|
|
If the code was:
It'd still be truthy even if no variables were "set" (they were actually set, explicitly to nil, but you get the idea) because [nil, nil] is truthy. It doesn't have anything to do with the values of the variables after the assignment, just what's on the right hand side.