From: Mark Beek Date: 2011-08-04T09:57:42+09:00 Subject: Kernel.load and local scope When I use a variable in a loaded file that corresponds to a variable in the local scope of the loading environment, I get an "undefined local variable or method" error. I'm not sure why. Here's a short file to demonstrate, with a top-level instance variable for comparison's sake: @var1 = 1 var2 = 2 puts "@var1: #{@var1}" puts "var2: #{var2}" load "external.rb" Here's external.rb: puts "external.rb @var1: #{@var1}" puts "external.rb var2: #{var2}" The result is: @var1: 1 var2: 2 external.rb @var1: 1 external.rb:2:in `': undefined local variable or method `var2' for main:Object (NameError) . . . Kernel.load documentation states: "In no circumstance will any local variables in the loaded file be propagated to the loading environment." Are we to infer that it also works the other way around? If so, why? Thanks, Mark B. -- Posted via http://www.ruby-forum.com/.