# What does $var mean?

**URL:** <https://www.ruby-forum.com/t/what-does-var-mean/127787>\
**Category:** Ruby\
**Created:** [February 1, 2008, 10:29am UTC](https://www.ruby-forum.com/t/what-does-var-mean/127787 "2008-02-01T10:29:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Magicloud\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47774/32.png) [@Magicloud\_M](https://www.ruby-forum.com/u/Magicloud_M)\
**Post date:** [February 1, 2008, 10:29am UTC](https://www.ruby-forum.com/t/what-does-var-mean/127787/1 "2008-02-01T10:29:52Z")

</div>

Hello,  
I mean what kind of variable is $var? What is its ‘domain’?

Thanks.

---

<div class="post-metadata">

**Author:** ![Magicloud\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47774/32.png) [@Magicloud\_M](https://www.ruby-forum.com/u/Magicloud_M)\
**Post date:** [February 1, 2008, 10:41am UTC](https://www.ruby-forum.com/t/what-does-var-mean/127787/2 "2008-02-01T10:41:08Z")

</div>

Alle Friday 01 February 2008, Magicloud M. ha scritto:

> Hello,  
> I mean what kind of variable is $var? What is its ‘domain’?
> 
> Thanks.

It’s a global variable. This means it’s visible from everywhere in your  
program.

Stefano C.

---

<div class="post-metadata">

**Author:** ![Magicloud\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47774/32.png) [@Magicloud\_M](https://www.ruby-forum.com/u/Magicloud_M)\
**Post date:** [February 1, 2008, 11:01am UTC](https://www.ruby-forum.com/t/what-does-var-mean/127787/3 "2008-02-01T11:01:04Z")

</div>

2008/2/1, Stefano C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Alle Friday 01 February 2008, Magicloud M. ha scritto:
> 
> > Hello,  
> > I mean what kind of variable is $var? What is its ‘domain’?
> > 
> > Thanks.
> 
> It’s a global variable. This means it’s visible from everywhere in your  
> program.

Sometimes it’s only thread global:

10:56:03 /cygdrive/c/SCMws/RKlemme/OPSC\_Gold\_bas\_dev\_R1.2\_cug  
$ ruby -e ‘(1…2).map {|i| Thread.new(i) {|a| /\d+/ =~ a.to\_s; 2.times  
{p [Thread.current, a, $&];}}}.each {|th| th.joi  
n}’  
[#\<Thread:0x1002fd7c run\>, 1, “1”]  
[#\<Thread:0x1002fbd8 run\>, 2, “2”]  
[#\<Thread:0x1002fd7c run\>, 1, “1”]  
[#\<Thread:0x1002fbd8 run\>, 2, “2”]  
10:59:31 /cygdrive/c/SCMws/RKlemme/OPSC\_Gold\_bas\_dev\_R1.2\_cug  
$

Kind regards

robert

---

<div class="post-metadata">

**Author:** ![Magicloud\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47774/32.png) [@Magicloud\_M](https://www.ruby-forum.com/u/Magicloud_M)\
**Post date:** [February 1, 2008, 11:03am UTC](https://www.ruby-forum.com/t/what-does-var-mean/127787/4 "2008-02-01T11:03:25Z")

</div>

Hi!

On Fri, Feb 1, 2008 at 10:29 AM, Magicloud M.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hello,  
> I mean what kind of variable is $var? What is its ‘domain’?

Every variable with a $ is a global variable. You can learn more about  
variables here:  
[http://phrogz.net/ProgrammingRuby/tut\_classes.html#classesobjectsandvariables](http://phrogz.net/ProgrammingRuby/tut_classes.html#classesobjectsandvariables)

Or as \_why puts it at [http://poignantguide.net/ruby/chapter-3.html:](http://poignantguide.net/ruby/chapter-3.html:)  
"Most variables are rather temporary in nature. Some parts of your  
program are like little houses. You walk in and they have their own  
variables. In one house, you may have a dad that represents Archie, a  
travelling salesman and skeleton collector. In another house, dad  
could represent Peter, a lion tamer with a great love for flannel.  
Each house has its own meaning for dad.

With global variables, you can be guaranteed that the variable is the  
same in every little house. The dollar sign is very appropriate. Every  
American home respects the value of the dollar. We’re crazy for the  
stuff. Try knocking on any door in America and hand them cash. I can  
guarantee you won’t get the same reaction if you knock on a door and  
offer Peter, a lion tamer with a great love for flannel."
