In this example,
def foo(x)
if(x > 5)
bar = 100
end
puts bar
end
Then foo(6) Outputs: 100
and foo(3) outputs nothing.
However if i changed the definition to
def foo(x)
if(x > 5)
bar = 100
end
puts bob
end
I get an "undefined local variable or method" error.
So my question is why I am not getting this error when I call foo(3) and bar is never set?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…