From: "Darryl L. Pierce" Date: 2012-01-20T21:19:39+09:00 Subject: Re: Understanding 'require' On 01/18/2012 06: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) > $ > var1 is not a global variable, but is instead scoped only to the content of test1a.rb. If you want to output it from test1 then you would need to declare it as: $var1='Hello, world!' The $ makes it global. -- Darryl L. Pierce http://mcpierce.multiply.com/ "What do you care what people think, Mr. Feynman?"