[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

what is the $ in varaiable

Junkone

12/27/2007 8:20:00 PM

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

Sebastian Hungerecker

12/27/2007 8:23:00 PM

0

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: sepp2k@jabber.org
ICQ: 205544826

Junkone

12/27/2007 8:49:00 PM

0

On Dec 27, 3:22 pm, Sebastian Hungerecker <sep...@googlemail.com>
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: sep...@jabber.org
> ICQ: 205544826

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

Sebastian Hungerecker

12/27/2007 8:54:00 PM

0

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
--
NP: Ulver - Ulveratternes Kamp
Jabber: sepp2k@jabber.org
ICQ: 205544826

Junkone

12/27/2007 8:59:00 PM

0

On Dec 27, 3:53 pm, Sebastian Hungerecker <sep...@googlemail.com>
wrote:
> 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
> --
> NP: Ulver - Ulveratternes Kamp
> Jabber: sep...@jabber.org
> 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.

Sebastian Hungerecker

12/27/2007 9:05:00 PM

0

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
--
NP: Loss of a Child - Missing
Jabber: sepp2k@jabber.org
ICQ: 205544826

Marc Heiler

12/27/2007 10:59:00 PM

0

> 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)
--
Posted via http://www.ruby-....

Robert Klemme

12/29/2007 10:00:00 AM

0

On 27.12.2007 23:58, Marc Heiler 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. :-)

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