Mark Beek wrote in post #1014828:
> 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?

Because local variables are local :-)

You get a new local scope inside every class definition introduced by 
the 'class' keyword, and inside every method definition introduced by 
the 'def' keyword. And as you found, whenever you load() a file.

The reason for keeping local variables local is very important, because 
in ruby you can call methods just by their bare name, and also reference 
local variables just by their bare name.

So if I were to write a piece of ruby code like this:

  puts var2

Ruby has to decide if v2 is a local variable, or if it's a method call. 
Note that if you force a method call, there's no ambiguity:

  puts var2()
  puts self.var2

But without this hint, it has to decide for itself. This decision is 
made at parse-time, not at run-time (which would be too inefficient). 
The rule is simple: inside the current scope, if you've seen a possible 
assignment to this variable - even if it is never executed - then it's a 
variable.

if false
  var2 = 123
end

puts var2    # nil
puts var3    # NameError: undefined local variable or method `v3'

-- 
Posted via http://www.ruby-forum.com/.