Try this instead:

# test1a.rb
VAR_ONE =3D "Hello, world!"

#test1
#!/usr/bin/env ruby
require './test1a'
puts VAR_ONE

$./test1
#=3D> Hello, world!


This is because Kernel#require, and also, Kernel#load will never leak
local variables into the global namespace.

Kernel#require and #load will however leak constants, and ofcourse
globals, but Kernel#load will wrap the source in an anonymous module
preventing global namespace leaking if you pass 'true' as the second
argument (ie: load('./test1a.rb', true) should result in a NameError
"uninitialized constant"; just make sure you include the '.rb' with
load)



On Wed, Jan 18, 2012 at 6:45 PM, Doug Jolley <ddjolley / gmail.com> wrote:
> I am clearly missing something WRT 'require'. I have a program file
> (test1) which requires another file (test1a). My content, etc. is shown
> below. =A0Why doesn't running test1 produce, 'Hello, world!' as output?
> Thanks for any input.
>
> =A0 =A0 =A0 =A0... doug
>
> $ ls
> test1 =A0test1a.rb
> $ cat test1a.rb
> var1=3D'Hello, world!'
> $ cat test1
> #!/usr/bin/ruby
>
> require './test1a.rb'
> puts(var1)
> $ ./test1
> ./test1:4: undefined local variable or method `var1' for main:Object
> (NameError)
> $
>
> --
> Posted via http://www.ruby-forum.com/.
>