From: Zachary Scott Date: 2012-01-19T12:42:58+09:00 Subject: Re: Understanding 'require' Try this instead: # test1a.rb VAR_ONE = "Hello, world!" #test1 #!/usr/bin/env ruby require './test1a' puts VAR_ONE $./test1 #=> 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 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.  Why doesn't running test1 produce, 'Hello, world!' as output? > Thanks for any input. > >        ... doug > > $ ls > test1  test1a.rb > $ cat test1a.rb > var1='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/. >