script local variables - the root of all mystery?

Discussion in 'Ruby' started by Jason Dusek, Sep 14, 2006.

  1. Jason Dusek

    Jason Dusek Guest

    I have a script with top level variables in it (i.e - variables that
    are not declared within a block, function definition or class
    definition). When I run this script through irb with load, I can
    access the variables just as though I had defined them in irb. Cool!

    Then I added a true global variable - $opts - to my script. I run it
    through irb and, lo and behold, I can't get at those top level
    variables anymore. What happenned? Did declaring the global variable
    somehow sink my script into its own context?
    --
    _jsn
    Jason Dusek, Sep 14, 2006
    #1
    1. Advertising

  2. Jason Dusek

    Jason Dusek Guest

    I don't know why this gets sent twice. All my other proxied mail
    accounts behave fine.
    --
    _jsn

    On 9/14/06, Jason Dusek <> wrote:
    > I have a script with top level variables in it (i.e - variables that
    > are not declared within a block, function definition or class
    > definition). When I run this script through irb with load, I can
    > access the variables just as though I had defined them in irb. Cool!
    >
    > Then I added a true global variable - $opts - to my script. I run it
    > through irb and, lo and behold, I can't get at those top level
    > variables anymore. What happenned? Did declaring the global variable
    > somehow sink my script into its own context?
    > --
    > _jsn
    >
    >



    --
    _jsn
    Jason Dusek, Sep 14, 2006
    #2
    1. Advertising

  3. Jason Dusek

    Guest

    Jason Dusek wrote:
    > I have a script with top level variables in it (i.e - variables that
    > are not declared within a block, function definition or class
    > definition). When I run this script through irb with load, I can
    > access the variables just as though I had defined them in irb. Cool!
    >
    > Then I added a true global variable - $opts - to my script. I run it
    > through irb and, lo and behold, I can't get at those top level
    > variables anymore. What happenned? Did declaring the global variable
    > somehow sink my script into its own context?


    I cannot exactly tell what went wrong in your case but I do know that
    IRB cannot be trusted once local variables are involved.

    Maybe post the script so we get a better impression of what is going
    on?

    Kind regards

    robert
    , Sep 15, 2006
    #3
    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. Replies:
    0
    Views:
    1,218
  2. Rick Osborn
    Replies:
    10
    Views:
    3,955
    Jon A. Cruz
    Feb 8, 2004
  3. Mark Shelor

    Mystery: static variables & performance

    Mark Shelor, Feb 7, 2004, in forum: C Programming
    Replies:
    122
    Views:
    2,238
  4. hector
    Replies:
    5
    Views:
    412
    CBFalconer
    Dec 5, 2006
  5. Sullivan WxPyQtKinter
    Replies:
    10
    Views:
    664
    Antoon Pardon
    Nov 8, 2007
Loading...

Share This Page