What is the $ in varaiable

what is the meaning of the $ in the variable
$tws = Twslinkrb::TWSLinkWrap.new(1)

Junkone wrote:

what is the meaning of the $ in the variable
$tws = Twslinkrb::TWSLinkWrap.new(1)

It marks the variable as global.

On Dec 27, 3:22 pm, Sebastian H. [email protected]
wrote:

Junkone wrote:

what is the meaning of the $ in the variable
$tws = Twslinkrb::TWSLinkWrap.new(1)

It marks the variable as global.


NP: Nile - The Infinity Of Stone
Jabber: [email protected]
ICQ: 205544826

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

On Dec 27, 3:53 pm, Sebastian H. [email protected]
wrote:

NP: Ulver - Ulveratternes Kamp
Jabber: [email protected]
ICQ: 205544826

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.

Junkone wrote:

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

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. :slight_smile:

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)

Junkone wrote:

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

On 27.12.2007 23:58, Marc H. wrote:

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. :slight_smile:

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. :slight_smile:

Kind regards

robert

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs