benjohn / fysh.org wrote:
>> Can Ceran wrote:
>>> Hi,
>>> I have also some another thing in Ruby that I am not sure about.
>>> What kind of storage binding is used in Ruby, as far as I understand
>>> there are no static variables (i'm not sure again), then Ruby uses
>>> both
>>> stack-dynamic and heap-dynamic variables or just stack-dynamic?
>> You can determine storage by the notation:
>>
>> stack
>> -----
>> x = 1
>> ... {|x|...}
>> def meth x
>>
>> heap
>> ----
>> @x = 1
>> @@x = 1
>> $x = 1
> 
> I'm pretty sure you're being misleading there. You can determine the
> _scope_ of a variable by it's notation / prefix.

Oops, right. That was very misleading. I was talking about where the 
variable is stored (which Robert explained better). The question was 
probably about where the _object_ is stored, and that's always on the heap.

The scope of a variable is not, strictly speaking, determined by prefix, 
however:

def foo
   x = 1
   3.times { x||=1; x+=1 }
   p x # ==> 4
end

def foo
   3.times { x||=1; x+=1 }
   p x # ==> NameError
end

-- 
        vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407