Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > script local variables - the root of all mystery?

Reply
Thread Tools

script local variables - the root of all mystery?

 
 
Jason Dusek
Guest
Posts: n/a
 
      09-14-2006
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

 
Reply With Quote
 
 
 
 
Jason Dusek
Guest
Posts: n/a
 
      09-14-2006
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

 
Reply With Quote
 
 
 
 
shortcutter@googlemail.com
Guest
Posts: n/a
 
      09-15-2006

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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can local function access local variables in main program? Sullivan WxPyQtKinter Python 10 11-08-2007 02:51 PM
while executing my client program i get the exception javax.naming.LinkException: [Root exception is javax.naming.LinkException: [Root exception is javax.naming.NameNotFoundException: remaining if plz anybody know how to solve this problem then mahesh Java 0 03-08-2007 12:26 PM
non root users accessing application installed with root instance hector C Programming 5 12-05-2006 01:01 PM
SRT DIvision, Square root and reciprocal square root alghazo@siu.edu VHDL 0 05-27-2004 06:23 AM
Tertiary Conditional: what does this evaluate to ("docRoot == null ? this.root : doc root")? Rick Osborn Java 10 02-08-2004 02:25 AM



Advertisments