I realy dont understand what Chris is talking about here in his book
“learning to program” Can someoe shed some light on this
def little_pest tough_var
tough_var = nil
puts ’ HAHA! I ruined your variable!’
tough_var = ’ You can’ t even touch my variable!’
HAHA! I ruined your variable!
You can’ t even touch my variable!
excerpt from his book:
In fact, two variables in that little program are named tough_var:
one inside little_pest and one outside of it. They donâ??t communicate.
They arenâ??t related. They arenâ??t even friends. When we called
little_pest tough_var, we really just passed the string from one
tough_var to the other (via the method call, the only way they can even
sort of communicate) so that both were pointing to the same string.
Then little_pest pointed its own local tough_var to nil, but that
did nothing to the tough_var variable outside the method.