I have a question about how the Ruby interpreter assigns variables:
I use this quite often:
return foo if (foo = bar.some_method)
where some_method returns an object or nil.
However, when I try this:
return foo if (true && (foo = bar.some_method))
I get: NameError: undefined local variable or method foo for main:Object.
What is the difference in evaluation between the first and second lines that causes the second line to error?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…