--Apple-Mail-71-840595374
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=US-ASCII; format=flowed

On 09 Feb 2005, at 16:15, benny wrote:

> just another ruby gotcha:
>
> to prevent namespace pollution from abitrary loaded files with code in 
> it, I
> had the idea to evaluate the code in anonymous modules, that are saved 
> in a
> hash (key is the filename/path).
>
> worked so far, no problem.
>
> then I tried to include the anonymous modules to have comfortable 
> access to
> the classes and methods of the corresponding files and guess what... it
> worked!
>
> include anonymous modules! whow! I am really impressed!
> this language let me try things I would not think about in other 
> languages.
>
> thank you matz and the other developers for this great language!

If you don't need to do anything with the anonymous namespace:

$ ri Kernel#load
------------------------------------------------------------ Kernel#load
      load(filename, wrap=false)   => true
------------------------------------------------------------------------
      Loads and executes the Ruby program in the file _filename_. If the
      filename does not resolve to an absolute path, the file is searched
      for in the library directories listed in +$:+. If the optional
      _wrap_ parameter is +true+, the loaded script will be executed
      under an anonymous module, protecting the calling program's global
      namespace. In no circumstance will any local variables in the
      loaded file be propagated to the loading environment.

$ cat x.rb
Foo = 5

puts "x here, is there a Foo? #{defined? Foo}"

$ cat y.rb
load 'x.rb', true

puts "y here, is there a Foo? #{defined? Foo}"

$ ruby y.rb
x here, is there a Foo? constant
y here, is there a Foo?

-- 
Eric Hodel - drbrain / segment7.net - http://segment7.net
FEC2 57F1 D465 EB15 5D6E  7C11 332A 551C 796C 9F04

--Apple-Mail-71-840595374
content-type: application/pgp-signature; x-mac-type=70674453;
	name=PGP.sig
content-description: This is a digitally signed message part
content-disposition: inline; filename=PGP.sig
content-transfer-encoding: 7bit

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Darwin)

iD8DBQFCCrCOMypVHHlsnwQRAhIaAJ9GBlt96iG278BwlrBobWDlpOZ1DACguUdO
HgELUTfVUEEf2n3D0R8JPHM=
=R3Ij
-----END PGP SIGNATURE-----

--Apple-Mail-71-840595374--