[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

script local variables - the root of all mystery?

Jason Dusek

9/14/2006 10:41:00 PM

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

2 Answers

Jason Dusek

9/14/2006 10:43:00 PM

0

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

On 9/14/06, Jason Dusek <jsn.s.rubix.cube@gmail.com> 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

Robert Klemme

9/15/2006 3:31:00 AM

0


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