S
Sam Kong
Hi, group!
This morning, a question came into my mind (I'm still a newbie).
What's the meaning of a top-level variable?
t = "top"
$g = "global"
puts t
puts $g
def f
puts t #error
puts $g
end
f
I know that a top-level variable cannot be used in a method.
My questions are:
1. Do you use top-level variables instead of global variables if you
don't need to use it in a method? Is it a good practice to use it like
that?
2. What is a top-level variable? Is it an object variable or a local
variable or what?
3. What is the exact scope of a top-level variable?
Thanks.
Sam
This morning, a question came into my mind (I'm still a newbie).
What's the meaning of a top-level variable?
t = "top"
$g = "global"
puts t
puts $g
def f
puts t #error
puts $g
end
f
I know that a top-level variable cannot be used in a method.
My questions are:
1. Do you use top-level variables instead of global variables if you
don't need to use it in a method? Is it a good practice to use it like
that?
2. What is a top-level variable? Is it an object variable or a local
variable or what?
3. What is the exact scope of a top-level variable?
Thanks.
Sam