what is the $ in varaiable

J

Junkone

It marks the variable as global.

how do global instance variables work. i am looking for some examples
espcially how the scope of the varaibles work.
thanks
 
S

Sebastian Hungerecker

Junkone said:
how do global instance variables work.

There's no such thing.
If a var starts with $, it's global, if it starts with @ it's an instance var.
It can't be both.

HTH,
Sebastian
 
J

Junkone

There's no such thing.
If a var starts with $, it's global, if it starts with @ it's an instance var.
It can't be both.

HTH,
Sebastian

ok. if i have $something, is it available to all the objects withtin
the program. for ex
i have opened $something
a.method invoks b.method.
does $something be available inside b.method without passing it.
can u point out some examples.
thanks in advance.
 
S

Sebastian Hungerecker

Junkone said:
ok. if i have $something, is it available to all the objects withtin
the program.

Yes, that's what global means.

i have opened $something
a.method invoks b.method.
does $something be available inside b.method without passing it.

Yes.


HTH,
Sebastian
 
M

Marc Heiler

if i have $something, is it available to all the objects withtin the program.

It is really totally global. You can access any global var from any
method. :)

In many cases though, you will find that in "typical" ruby code there is
not really the need to use many global variables (but instead local, and
@instance vars)
 
R

Robert Klemme

It is really totally global. You can access any global var from any
method. :)

There are however some variables that are gloabal but thread local (all
globals that are affected by regular expression matching).
In many cases though, you will find that in "typical" ruby code there is
not really the need to use many global variables (but instead local, and
@instance vars)

And in fact, globals are often considered bad practice - not just in
Ruby but more generally. :)

Kind regards

robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,274
Messages
2,571,370
Members
48,062
Latest member
leehaan

Latest Threads

Top