On Tuesday, July 31, 2012 at 3:29 PM, SASADA Koichi wrote:
> Now, `require' only loads `.rb' script or `.so' files from `file system'.
> 
> (Proposal-1)
> This proposal extends the current limitation of require:
> 
> (1) load script which is represented by other than `.rb' and `.so'.
> (example: pre-compiled file, encrypted file)
> 
> (2) load script from location from other than `file system'.
> (example: require from zip archive, require over network,
> require files provided by gem efficiently using file location db)
> 
> 


I'll echo what Charles said in his response: file lookup and code loading should be handled independently. I would even go so far as to say that code loading could be made an independent API from require, enabling the loading of code from memory or, say, from a network socket. 

> == Related work
> 
> === JRuby
> 
> JRuby can require file from `.jar' (and .war file? sorry i'm not sure).
> JRuby also extends file path like VFS (virtual file system). JRuby can
> open a file in a .jar file like file system.
> (JRuby GURU: Please complement this section!)
> 
> === Rubinius
> 
> Rubinius supports AOT compile (a ruby script to a compiled file).
> (Rubinius GURU: Please complement it!)
> 
> 


=== MacRuby

MacRuby has modified require to be able to load compiled and linked object files (*.rbo) like so:

Earth: ~/Desktop > echo "def foo; puts 'foo from file a.rb'; end" > a.rb
Earth: ~/Desktop > echo "require 'a'; foo" > b.rb
Earth: ~/Desktop > macrubyc -C a.rb
Earth: ~/Desktop > macrubyc -C b.rb
Earth: ~/Desktop > rm a.rb b.rb
Earth: ~/Desktop > macruby -e "require './b'"
foo from file a.rb

But, beyond that, MacRuby can also "require" a file in a compiled, linked, dynamic library:

Earth: ~/Desktop > echo "def foo; puts 'foo from file a.rb'; end" > a.rb
Earth: ~/Desktop > echo "require 'a'; foo" > b.rb                       

Earth: ~/Desktop > macrubyc a.rb b.rb -o ab.dylib --dylib

Earth: ~/Desktop > rm a.* b.*

Earth: ~/Desktop > echo "require 'b'" > c.rb

Earth: ~/Desktop > macrubyc c.rb ab.dylib -o awesome

Earth: ~/Desktop > ./awesome
foo from file a.rb


Right now, we accomplish this with a variety of "tricks" (i.e. features of OS X's dynamic loader), but it would be nice to have a more formalized API for doing the same thing.