Jacob Fugal
3/8/2006 11:28:00 PM
On 3/8/06, rtilley <rtilley@vt.edu> wrote:
> Bernhard 'elven' Stoeckner wrote:
> > rtilley wrote:
> >>Or, is it OK to use them like this:
> >>
> >>global_var
> >>def some_other_function
> >> ...
> >> global_var
> >>end
> >
> > No, you still need to use either global or instance variable syntax, since
> > it is, as you correctly state, still a class.
>
> OK, but the script works wheter I use $ for globals and @ for instance
> variables or not. With small scripts, why does it matter?
I'm curious what your script is then. Because the variable will not be
shared -- the global_var inside some_other_function is different than
the global_var outside the function. Try this:
$ irb
>> global_var = 2
=> 2
>> def test1
>> global_var
>> end
=> nil
>> def test2
>> global_var = 5
>> end
=> nil
>> global_var
=> 2
>> test1
=> nil
>> test2
=> 5
>> global_var
=> 2
Jacob Fugal