为什么最后一个语句(语句末尾的"if(tmp2 = foo)")失败?
def foo;5;end
# this one works
if (tmp = foo)
puts tmp.to_s
end
# why this one fails
puts tmp2.to_s if (tmp2 = foo) #=> undefined local variable or method ‘tmp2’ for main:Object
Run Code Online (Sandbox Code Playgroud) ruby ×1