On Dec 18, 2005, at 12:02 PM, Grehom wrote:

> I have one line of code in a file called 'stuff.rb':
>      myhash = { "a" => "ay", "b" => "bee", "c" => "sea" }
>
> and I wish to include it in another program called 'mainprog.rb' thus:
>
>      require 'stuff'
>
>      puts " a = " + myhash["a"]
>
> when I run it I get an error message:
>     mainprog.rb:4: undefined local variable or method `myhash' for
> main:Object (NameError)
>
> I guess I must be doing something dumb - I am basing this code on
> examples in 'Why's (poignant) guide to Ruby'.  I am using the very
> latest Windows version under XP Pro:
> C:\rubysrcs>ruby -v
> ruby 1.8.2 (2004-12-25) [i386-mswin32]
>
> which I installed using the exe file: ruby182-15.exe
>
> everything else I've tried seems to be working fine.  Thanks.
>
>

Try using this instead:

load 'stuff'

local variables outside of  class like that will not be imported when  
you require that file. Load should do what you want.

Cheers-

-Ezra