Michael Judge wrote:
>
>   ["a","b"].each do |name|
>     sandbox = Module.new { require "#{name}.rb" }
>
>     survey = sandbox::Survey.new
>
>     puts survey.name
>   end
>
> This is what I'd like to do, but 'name' is out of scope and when I
> hardcode it, it seems like require is pulling class Survey from the file
> into the global namespace rather than the anonymous module's namespace.
> It's weird.

It's not weird. Require (or load) is going to load the script normally
and return true or false; that line is (except for order of execution)
the same as this:

x = require "#{name}.rb"
sandbox = Module.new { x }

If what you want is for the script's code to be evaluated in the
context of the module, you need to use module_eval, as seen in the
latest ruby-dev summary:

sandbox = Module.new
sandbox.module_eval File.read("#{name}.rb")

Cheers,
Dave