tags:

views:

39

answers:

2

Would it be possible to override the default "require" by adding automatic download-and-install code for any missing includes (provided that the missing include is published as a ruby gem).

Which would not work in situations where Ruby is not interfaced with a shell. But still I think it would be an interesting idea.

Is there such a mechanism in existence today?

Edit:
Removed portion about password check. I just checked and gem install doesn't seem to require me to type my password.

+1  A: 

You would be able to hijack require method so as gems are installed when an attempt is made to require them, but still you won't have access to newly installed gem in current process, because gem index has to be reloaded.

I understand the intentions but I think exercise might not be worth it.

Hemant Kumar
A: 

When installing a fresh gem the gem will be installed in the GEM_HOME. If that is not writable then it will try in the user's home .gem directory (on *NIX at least).

You could certainly script this. In a way Rail's rake gems:build is just this. Just not on demand.

But, I would recommend against this. You could run into build, versioning, dependency and network issues. And probably security issues as well.

PS: Francis Hwang did something related a while ago, although only as a require, not a require gems.

http://fhwang.net/2005/11/01/urirequire-I-got-yer-Web-2-0-right-here

The Who