What does $var mean?

Discussion in 'Ruby' started by Magicloud Magiclouds, Feb 1, 2008.

  1. Hello,
    I mean what kind of variable is $var? What is its 'domain'?

    Thanks.
     
    Magicloud Magiclouds, Feb 1, 2008
    #1
    1. Advertising

  2. Alle Friday 01 February 2008, Magicloud Magiclouds 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 Crocco
     
    Stefano Crocco, Feb 1, 2008
    #2
    1. Advertising

  3. 2008/2/1, Stefano Crocco <>:
    > Alle Friday 01 February 2008, Magicloud Magiclouds 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


    --
    use.inject do |as, often| as.you_can - without end
     
    Robert Klemme, Feb 1, 2008
    #3
  4. Hi!

    On Fri, Feb 1, 2008 at 10:29 AM, Magicloud Magiclouds
    <> 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

    Or as _why puts it at 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."
     
    Thomas Wieczorek, Feb 1, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fred
    Replies:
    3
    Views:
    342
    Alf P. Steinbach
    Aug 10, 2003
  2. Ming
    Replies:
    5
    Views:
    533
  3. Chih-Chao Lam

    What does *var mean?

    Chih-Chao Lam, Aug 25, 2006, in forum: Ruby
    Replies:
    12
    Views:
    185
  4. Replies:
    9
    Views:
    182
  5. Lison Allen

    What does "var a = a || {};" mean?

    Lison Allen, Mar 26, 2011, in forum: Javascript
    Replies:
    0
    Views:
    102
    Lison Allen
    Mar 26, 2011
Loading...

Share This Page